Archived topic
Container Dynamic Link adds invalid link
17 replies · Started by Shane on January 24, 2022
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?
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. :D
Hello!
Using get_field('link_url') on the page does return the value.
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.
Hi Shane,
If you add this dynamic link to a headline block, does the link work?
Yes it does, just not the container
Can you link us to the page where we can see the issue?
Added via private message
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;
}
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?
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).
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.
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?
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!
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.