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.
The Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <?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(); ?> |
This query works fine. Can’t i query for term by term_id ( for all type of term )?