Home › Forums › General Issues › Taxonomy field in array › Reply To: Taxonomy field in array
Hi @sagi
First, please make sure that you’ve set the “Return Value” to “Term ID”. This setup will make it returns an array of IDs from the selected taxonomies. That way, you don’t need to wrap the returned value in an array.
Second, “category__and” args is used to show posts that have all of the selected taxonomies. If you want to show posts that have minimum one of the selected taxonomies, please use “category__in” instead. This page should give you more idea about it: https://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters.
So it should be something like this:
$kat = get_field('taxonomy');
$args = array(
'posts_per_page' => 5,
'category__in' => $kat, //change to category__and if you want to match all selected taxonomies
);
$my_query = new WP_Query( $args );
while( $my_query->have_posts() ):
$my_query->the_post();
the_title();
endwhile;
wp_reset_postdata();
If you want to check the returned value, please use the var_dump() function. This page should give you more idea about it: http://www.advancedcustomfields.com/resources/debug/.
I hope this helps.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.