Site logo

[Resolved] Container Dynamic Link adds invalid link

Home Forums Support [Resolved] Container Dynamic Link adds invalid link

Home Forums Support Container Dynamic Link adds invalid link

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #2092371
    Shane

    when trying to create a container with a dynamic link and acf field, a link is created but the value is #, as it just adds that to the url value field.

    The link href value on the frontend is #.

    Any idea why?

    #2092388
    Elvin
    Staff
    Customer Support

    Hi Shane,

    For this specific single post, can you try doing a var_dump() for this particular custom field?

    To know if the link_url field is returning a value. If it doesn’t return a value, can you check the post’s link_url field if it has a url in it? can you also verify if the custom field handle is correct?

    Let us know. 😀

    #2093398
    Shane

    Hello!

    Using get_field('link_url') on the page does return the value.

    #2093450
    Shane

    Just to add some more context…

    I’m having this issue with a Container module which lives inside of a Left Sidebar Element. That sidebar is inserted into a Custom Post Type. So the ACF field that I’m trying to pull in lives on the CPT object.

    #2093558
    Ying
    Staff
    Customer Support

    Hi Shane,

    If you add this dynamic link to a headline block, does the link work?

    #2093559
    Shane

    Yes it does, just not the container

    #2093590
    Ying
    Staff
    Customer Support

    Can you link us to the page where we can see the issue?

    #2093605
    Shane

    Added via private message

    #2093696
    Ying
    Staff
    Customer Support

    Hum..it does look like a bug to me, we will look into it.

    For now, can you try replace one of the headlineblock (eg. software ->)in the container with a buttonsblock, and add the dynamic link to the buttonsblock.

    Then add this CSS to make the container clickable:

    .gb-container.guide-sidebar-cta a:before {
        content: '';
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
    }
    .gb-container.guide-sidebar-cta {
        position: relative;
    }
    #2093800
    Shane

    Hello, that’s done.

    Also, when using the page link ACF field, the return value is an ID of the selected post link. Is this a bug?

    #2093831
    Elvin
    Staff
    Customer Support

    Hi Shane,

    ACF fields of specific types have an option to return an ARRAY, ID or a single value. You may have to check and verify if this particular field has the preferred value(it should be single).

    #2094786
    Shane

    Hi, just want to clarify that the button solution didn’t work, as using ACF’s page_link field, which doesn’t have an option to select a single value or id, only outputs the ID of the selected post. Also tried Link type and that doesn’t output a value at all.

    #2094958
    Shane

    Okay this works when ACF is a text field, but doesn’t work when it’s a link page and a field.

    Seems like this is a hack workaround, but is there anyway to look into the bug so the container can work as expected?

    #2095258
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    This is a confirmed bug where the custom field value doesn’t work in Container links. It will be fixed in the next GPP update.

    For now, you can do something like this:

    add_filter( 'generateblocks_attr_container-link', function( $attributes, $settings ) {
        $link_type = ! empty( $settings['gpDynamicLinkType'] ) ? $settings['gpDynamicLinkType'] : '';
    
        if ( $link_type && '' !== $settings['url'] && ( 'wrapper' === $settings['linkType'] || 'hidden-link' === $settings['linkType'] ) ) {
            $id = get_the_ID();
    
            if ( ! $id ) {
                return $attributes;
            }
    
            if ( 'post-meta' === $link_type ) {
                if ( ! empty( $settings['gpDynamicLinkCustomField'] ) ) {
                    $custom_field = get_post_meta( $id, $settings['gpDynamicLinkCustomField'], true );
    
                    if ( $custom_field ) {
                        $attributes['href'] = esc_url( $custom_field );
                    }
                }
            }
        }
    
        return $attributes;
    }, 20, 2 );

    That should fix the bug. If the ACF field isn’t working, we may need to see what kind of value to expect. If that’s the case, replace this:

    $custom_field = get_post_meta( $id, $settings['gpDynamicLinkCustomField'], true );

    With this:

    $custom_field = get_post_meta( $id, $settings['gpDynamicLinkCustomField'], true );
    var_dump($custom_field);

    And let us know what kind of debug code shows on the frontend with the posts.

    Thanks!

    #2096397
    Shane

    Hello!

    I updated the container and content with how it was previously, and also added the snippet of code you provided.It seems to work.

    I changed the ACF field to page link and the value that outputs is the selected page ID.

    I also tested this with get_field() and the output is a url.

Viewing 15 posts - 1 through 15 (of 18 total)
  • You must be logged in to reply to this topic.