Posted By

f6design on 11/30/11


Tagged

wordpress taxonomy


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

CreativeNerds


Wordpress: Query a custom taxonomy


 / Published in: PHP
 

Use WPQuery to query a custom taxonomy, using the taxquery parameter.

  1. <?php
  2. // Example query to select all posts belonging to a custom taxonomy.
  3. $args = array(
  4. 'tax_query' => array(
  5. 'taxonomy' => 'TAXONOMY_NAME',
  6. 'field' => 'slug',
  7. 'terms' => 'TAXONOMY_SLUG'
  8. )
  9. )
  10. );
  11. $the_query = new WP_Query( $args );
  12.  
  13. // The Loop
  14. while ( $the_query->have_posts() ) : $the_query->the_post();
  15. echo '<li>';
  16. the_title();
  17. echo '</li>';
  18. endwhile;
  19.  
  20. // Reset Post Data
  21. wp_reset_postdata();
  22. ?>

Report this snippet  

You need to login to post a comment.