Home Forums General Issues Query posts via Taxonomy field Reply To: Query posts via Taxonomy field

  • So what you need to do is get the ACF field, which will return an array of term IDs and use that array to do a WP_Query, similar to what magicstick posted.

    For this you need to set the taxonomy field on the book edit page to return Term ID, if it’s returning Term Object it will be a bit more complicated.

    $topics = get_field('topics');
    if ($topics) {
      if (!is_array($topics)) {
        $topics = array($topics);
      $args = array(
        'post_type' => 'quotes',
        'posts_per_page' => 5,
        'orderby' => 'rand',
        'tax_query' => array(
            'taxonomy' => 'topics',
            'terms' => $topics,
      $quote_query = new WP_Query($args);
      if ($quote_query->have_posts()) {
        while($quote_query->have_posts()) {
          echo '<p>',get_the_content(),'</p>';