WP: Query by taxonomy value

Apr 6, 2011

Here’s a simple way to create a custom query for posts by term value. It’s pretty straight forward but if you see a way to improve it, feel free to let me know.

<?php
// Define the arguments for the query here.
$args=array(
  'taxonomy' => 'taxonomy_slug_here',
  'term' => 'term_slug_here',
  'post_type' => 'custom_post_type_slug_here',
  'posts_per_page' => -1,
  'caller_get_posts'=> 1,
  'orderby'=> 'post_date',
  'order'=> 'ASC',
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
   while ($my_query->have_posts()) : $my_query->the_post(); ?>
    Call the post content here
   <?php endwhile; 
} wp_reset_query(); ?>