Skip to content
Advertisement

How do I get and set Advanced Custom Fields data as a variable in Timber $context to use in a post query?

I want to get and set the value of an ACF field into a variable in my home.php file and then use this as part of a query.

So, for example, if a user enters the word ‘event’ in the the field ‘cat_name’ in the CMS, I wanted to get and set this as a variable and then use this as part of a basic query to return all posts with a category of event..

What I have at the moment is below. How do I access ACF data in home.php / $context and then store it in the $my_var variable. Is this possible?

JavaScript

Advertisement

Answer

You need to get the field value with the TimberPost method get_field() :

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement