wp query – Get access to all terms associated to each post that the wp_query loop displays

Question

If the following loop logic gives me access to post properties that are associated to a CPT (for example, ‘sports’)…


   $args = array(
        'post_type' => 'sports',
        'posts_per_page' => -1
      );
      $query = new WP_Query($args);


      if ($query->have_posts()) : ?>

        <?php while ($query->have_posts()) : $query->the_post(); ?>

         //All the stuff I do...

Then from within the loop, how can I query for all terms that are associated to each of the ‘sports’ posts?

  • Under this ‘sports’ CPT, I have 3 taxonomies (‘basketball’, ‘volleyball’, ‘baseball’).
  • Each of these taxonomies have multiple terms under them.
  • I want each post that is provided from this wp_query loop, to have access to all the terms that are associated to their own post, and write them out (i.e. print_r $query->terms_array) from within the loop;

Is this possible?

0
klewis 2 weeks 2022-09-15T15:46:52-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse