How to get and set ACF data as a variable in $context
-
Hi.
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 get the value of get_field(‘cat_name’) and then store it in the $my_var variable. Is this possible?
<?php $context = Timber::get_context(); $context['post'] = new Timberpost(); $my_var = get_field('cat_name'); $context['posts'] = Timber::get_posts(array( 'post_type' => 'post', 'category_name' => $my_var )); Timber::render('home.twig', $context); ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘How to get and set ACF data as a variable in $context’ is closed to new replies.