Archived topic
Dynamic link data set on GB button in Block Element not populating correctly
7 replies · Started by Gary on July 7, 2022
Hi Support
I've got a page hero block element set up which I'm using display rules to show for certain pages. On those pages I have some ACF fields set up so the client can populate the page hero template easily. One of those fields is a link using ACF's link field which I've attached to a GB button.
The text values come through fine using the dynamic post meta option, but setting the dynamic link on the GB button I have nothing coming through? I've used both the old and new ways of adding the dynamic link to the button but neither way is working.
I've also checked and the ACF field is set correctly to only return the URL string (not an array). And if I use the ACF provided shortcode in the page hero template it returns the url as expected so the field appears to be doing what it should.
Anybody had any success with doing similar with ACF or is there some sort of limitation with GB's post meta option and certain ACF fields like ACF's Link?
Thanks
Hi Gary,
It should work, I just tested on my end and the URL works fine.
Here're my settings for your reference:
https://www.screencast.com/t/DH2jAAVnutSS
Hi Ying
Thanks for the reply. I’m actually using an ACF link field. Looks like you might be using the Url field which is slightly different. The reason I’m using the link field over url one is the field has a nicer UI and makes it easier to link to internal pages by searching. That way the client doesn’t have to type page links in manually. I’m also adding the dynamic link value to a GB button in a page hero element.
Does the link field work for you if you replicate the setup above?
Thanks
Hum, it does not work when the ACF field is set to link type.
Try this PHP snippet, replace the custom_field_link with your custom field name.
add_filter( 'generateblocks_dynamic_url_output', function( $url, $attributes ) {
if ( 'post-meta' === $attributes['dynamicLinkType'] && isset( $attributes['linkMetaFieldName'] ) ) {
if ( 'custom_field_link' === $attributes['linkMetaFieldName'] ) {
$custom_field_link = get_field('custom_field_link');
if( $custom_field_link ):
$link = esc_url($custom_field_link);
return $link;
endif;
}
}
return $url;
}, 10, 2 );
Hi Ying
Thanks for the filter, it works great and now the link value is returned using the new dynamic data settings!
I guess therefore the issue was how the ACF link field stores its value versus the more basic url field.
Out of interest is there a reference anywhere yet for GB specific filters?
Thanks
I read this: https://www.advancedcustomfields.com/resources/link/
Then tried to call the data usingget_field() which is an ACF function.
You can find the filter here: https://github.com/tomusborne/generateblocks/blob/32825373b8f8ef895518018ff9ab306d2b7b7005/includes/class-dynamic-content.php#L843
Hi Ying
Thanks for this info.
Sorry I was meaning is there anywhere all the GB specific filters are referenced like with the GP filters in the docs? Had a look but couldn’t find anything!
If not no worries, would just be useful to have a reference as I think I’ve seen some other GB specific filters mentioned in other posts.
Thanks
Sorry I was meaning is there anywhere all the GB specific filters are referenced like with the GP filters in the docs?
Ah I see what you mean, unfortunately, we haven't got that doc yet.