Archived topic
ACF Page link in dynamic elements
5 replies · Started by Andrew on February 16, 2022
Heya. I can't seem to get ACF Page Link fields working in dynamic blocks in an Element.
If I set a standard text field I can get a Headline and Button linking by entering the Page URL but this is a not very user friendly. Is there any reason this would not return a page URL as per a basic text field? Thanks.
Hi Andrew,
There's a known bug that may be related to this.
See Tom's workaround here - https://generatepress.com/forums/topic/container-dynamic-link-adds-invalid-link/#post-2095258
It requires a bit of PHP, here's how to add it on your site - https://docs.generatepress.com/article/adding-php/
Let us know if you need clarification. :D
Thanks Elvin. That filter relates to Container links. Do I need a different filter for a button?
*edit: FYI It's a CPT and custom taxonomy but not sure if that's relevant. Working site is here:
https://valleyseeds.com.au/varieties/lucerne/
Ah yes that's right. For the button you'll need the generate_dynamic_element_url.
Can you specify which button has the issue? So I can check for clues as to what exactly is happening to it.
To be sure if the issue is w/ how or what format the link is being returned as by ACF. :)
For some reason it's outputting the page ID, not the URL.
https://valleyseeds.com.au/varieties/deep-rooted-perennial/
If I output the value in a dynamic Headline text block it returns the post ID, not the URL. If I try and add it as a button link it just returns the current url.
I can't work it out - the ACF function should be returning the url as per the documentation
https://www.advancedcustomfields.com/resources/page-link/
I might just try and render this button out using a shortcode.
I might just try and render this button out using a shortcode.
That can work. But to solve the issue directly, we can continue with the debug.
Can you do a var_dump() of this page's meta? particularly, the key used for page link?
Something like var_dump(get_post_meta(get_the_ID(),'key_of_page_link',false)); and have it displayed on the front-end so we can analyze it.