Is it possible to sort posts (custom post type) by category / taxonomy (name, desc)?
For example my categories would be
- Season 2012
- some post
- some post
- some post
- Season 2011
- some post
- some post
- some post
- Season 2010
- etc..
3 Answers
One solution would be-
$terms = get_terms('taxonomy-name');
foreach($terms as $term) {
$posts = get_posts(array(
'post_type' => 'custom_post_type_name',
'tax_query' => array(
array(
'taxonomy' => 'taxonomy-name',
'field' => 'slug',
'terms' => $term->slug
)
),
'numberposts' => -1
));
foreach($posts as $post) {
// do what you want to do with the posts here
}
}