Created
May 14, 2013 23:13
-
-
Save thoronas/5580467 to your computer and use it in GitHub Desktop.
Query posts from every term in a taxonomy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$terms = get_terms('taxonomy'); | |
$count = count($terms); | |
//check if there are any terms | |
if ( $count > 0 ){ | |
//loop through each term and query posts. | |
foreach($terms as $term){ | |
$term_args = array( | |
'post_type' => 'post type', | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'taxonomy', | |
'field' => 'slug', | |
'terms' => $term->slug | |
) | |
) | |
); | |
$term_posts = new WP_Query($term_args); | |
if($term_posts->have_posts()): | |
while($term_posts->have_posts()): $term_posts->the_post(); | |
the_title(); | |
the_content(); | |
endwhile; wp_reset_query(); | |
endif; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment