I have a site that lists upcoming events and past events.
In my category-past-event.php template, this is how I've gotten past events appear in descending order (from most recent to oldest):
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' => 100,
'paged' => $paged,
'cat' => 3709,
'orderby' => 'meta_value',
'meta_key' => 'Deadline', //formatted YYYYMMDD
'order' => 'desc'
);
query_posts($args);
?>
This setup successfully lists events in the order they appeared, e.g.
- Event 6
- Event 5
- Event 4
- Event 3
- Event 2
- Event 1
How can I get it so that the past events are broken up by month? E.g.
December 2012
- Event 6
- Event 5
- Event 4
November 2012
- Event 3
- Event 2
- Event 1
Update: I have set up pre_get_posts in functions.php as @s_ha_dum suggests and this is working.
@KrzysiekDróżdż, the problem I have is that the Deadline might not correspond to get_the_time('F Y').
This is because I might create a post with the Deadline = 20131212 (i.e. taking place in December 2013), but the time of that post might be different. I.e. it is June, and I create an upcoming event for December, the time of that post is June because I created it in June.
Currently using this on a production site (though I am testing locally with MAMP). The workflow for creating events is that posts are categorized as Events, and then the Post Expirator plugin switches their category to Past-Event once the date of the event has passed. Deadline exists so the posts can be sorted in ascending or descending order.
Still trying to wrap my head around how in the loop in category-past-event.php I would use that Deadline to sort them by month