I’m trying to echo out the value of my Taxonomy field to a WP Query on the same page. I have:
<?php
$cats = get_field('rel_posts_cat');
$my_query = new WP_Query(array(
'showposts' => '10',
'category__and' => array($cats),
));
while ( $my_query->have_posts() ) : $my_query->the_post();
?>
<?php the_title() ?>
<?php endwhile;?>
But nothing displays, even though I have selected a few categories in the CMS. Also, if I add these manually i.e.
'category__and' => array('1,12'),
Then that also works.
I’m presuming I’m doing something very silly!
Thanks in advance for anybody’s help.
Assuming the $cats
is receiving values it seems like you’ll want to update the code to:
<?php
$cats = get_field('rel_posts_cat');
$my_query = new WP_Query(array(
'showposts' => '10',
'category__and' => $cats,
));
while ( $my_query->have_posts() ) : $my_query->the_post();
?>
The change is on the 'category__and'
parameter, since $cats should be returning an array assuming you’ve defined the Return Value
to Term ID
Perfect. Thanks so much for your help with this @ractoon