I have a wordpress custom post type of "awards", which has a custom taxonomy of "awardyear." I'm trying to write a query that will list them all out, but group them by year, and have the year in a heading. For example all of the awards from the year 2010 would be grouped together & have "2010" as the header. Is this even possible? I'm able to get them all listed out, however, it's currently listing them all out under each year. Here is my current query:
$taxonomy = 'awardyear';
$queried_term = get_query_var($taxonomy);
$terms = get_terms($taxonomy, 'slug='.$queried_term);
$args = array(
'post_type' => 'awards',
'posts_per_page' => -1 ,
'awardyear' => $term->name,
'order_by' => 'awardyear',
'order' => 'ASC'
);
if ($terms) {
foreach($terms as $term) {
echo '<span class="award_year">' . $term->name . '</span> ';
query_posts( $args );
// The Loop
while ( have_posts() ) : the_post();
echo '<li style="list-style: none;">';
echo '<a href="';
the_permalink();
echo '">';
the_title();
echo '</a>';
echo '</li>';
endwhile;
// Reset Query
wp_reset_query();
}
}
Example output would be:
2010
Award Example Number 1
Award Example Number 2
2011
Award Example Number 1
Award Example Number 2
Award Example Number 3
Award Example Number 4
2012
Award Example Number 1
Award Example Number 2
Award Example Number 3