Site logo

Archived topic

ACF File Field as Content Template Dynamic Link

26 replies · Started by Matt on September 26, 2022

Viewing posts 16–27 of 27

Are you able to provide screenshots of your setup for the site that has this working?

Based on your last commment, the fact that the dynamic population functionality uses the 'get_post_meta' function, means that it doesn't use acf's 'get_field' function to turn the id into a url.

Hmm.. I can't seem to get this to work.

Are there any hooks I can use to programatically add the link through my child theme?

In your Content Template? You can add a portable Shrotcode.

Can you first try updating to the Release versions of GenerateBlocks and GenerateBlocks Pro?: https://generateblocks.com/account/

Hi Fernando,

I have done this and no change. I actually can't see how getting the file URL would ever work. If GB code uses get_post_meta() function to return the meta value, and GB doesn't have any specific intergration with ACF, then the settings I have on ACF to return a 'array', 'url' or 'file_id' would never be run as these are applied when using the acf get_field() function.

I mean a php hook that I can tap into and set my own link url. I can't see how any shortcode would be useful here as I want to add the link to the outer GP container.

Thanks

There's a filter to alter the rendered block but can you try creating a field type text instead of a url, and test that instead?

What is the filter you are referring to?

I can see that the value being returned from the file upload matches exactly what is in the post_meta table for that key (ie. 1672). So I am confident that the GB post_meta functionality is returning exactly what is in the DB and working as expected, and if I put a text value (eg. https:google.com) in there it would work as expected.

The issue is that ACF would normally retrieve the post_meta value (via the get_field() function) and then, based on the options set in the field settings, look up some other data in the DB to return and array, url or id. Unless, GB hooks into the ACF functionality (which I'm sure it doesn't), I can't see that this is going to work at all.

ACF should be retrievable with get_post_meta(). get_post_meta() is a core WordPress function. They just added another way - get_field - for simplification and other data retrieving features. But the core WordPress function should work as well since it still just a post meta.

See some cases here where the return value isn't working for ACF:

https://support.advancedcustomfields.com/forums/topic/image-returns-id-no-matter-what-return-value-is-set/

https://stackoverflow.com/questions/65346568/acf-relationship-field-return-id-instead-of-object-wordpress-timber-twig

Can you try #1 here to test?: https://docs.generatepress.com/article/debugging-tips/

Hi Fernando,

I think that we agree. I don't think this is an issue with Generatepress/ GenerateBlocks. I just don't think what I am trying to do is possible with a 'file upload' type ACF meta field.

The get_post_meta() is retrieving exactly what is in the database for this post_id and key (ie. 'file_upload') .... which is the number '1672'.

The ACF get_field() function uses the get_post_meta() function to retrieve the initial value, but then evaluates the selected return format (as selected in ACF settings) and uses this to generate the requested format/value. If GP/GB doesn't use get_fields(), then I can see why I am not getting the result I was wanting.

I'm happy to close this off now. Thanks for all of your assistance!

Next version of GB (1.6) we are adding ACF support and we are using the ACF get_field function.

You can test the last release candidate here GenerateBlocks 1.6 RC2

This archived topic is closed to new replies.