Home › Forums › General Issues › Help with Taxonomy Field Querying Multiple Taxonomy Terms › Reply To: Help with Taxonomy Field Querying Multiple Taxonomy Terms
Thanks so much for the reply. I was making this way more complicated than it needed to be. The Taxonomy Field:
$selected = get_field('selected_tags');
was already returning an array of IDs making my variable:
$selectags = implode(",",$selected);
completely unnecessary. Working code is below. Hopefully it’ll save somebody else some time & trouble.
<?php $postnumber = get_field('number_of_posts'); //custom field for posts per page $selected = get_field('selected_tags'); // ACF Taxonomy Field (Return Value = Term ID) ?> <?php $args = array( 'posts_per_page' => $postnumber, 'orderby' => 'post_date', 'order' => 'ASC', 'post_type' => 'post', 'post_status' => 'publish', 'tag__in' => $selected ); ?> <?php query_posts($args); if (have_posts()) : while (have_posts()) : the_post(); ?> <h2><?php the_title(); ?></h2> <p><?php the_excerpt(); ?></p> <a href="<?php the_permalink() ?>">read the post</a> <p><?php the_tags('Tags: ', ', ', ''); ?></p> <?php endwhile; endif; ?> <?php wp_reset_query(); ?>
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!
The ACF site is currently experiencing some issues.— Advanced Custom Fields (@wp_acf) September 29, 2022
We apologize for the inconvenience and we are working hard to get it back up and running as soon as possible.
© 2022 Advanced Custom Fields.