Ok short of a better solution here is what I’ve come up with:
<?php
$today = date('Y-m-d', strtotime('-6 hours'));
query_posts(array(
'post_type' => 'events', 'posts_per_page' => 99, 'meta_key' => 'event_date', 'orderby' => 'meta_value', 'order' => 'ASC',
'meta_query' => array(array(
'key' => 'event_date',
'meta-value' => $value,
'value' => $today,
'compare' => '>=',
'type' => 'CHAR'
))
));
if (have_posts()) :
while (have_posts()) : the_post();
?>
The above gets all events in future of todays date
<?php
// http://stackoverflow.com/questions/3586384/wordpress-events-grouped-by-month
// for each month output the month once
$eventdate = get_post_meta($post->ID, "event_date", true);
if(!isset($currentMonth) || $currentMonth != date("m", strtotime($eventdate))){
$currentMonth = date("m", strtotime($eventdate));
//make the month to pass into the url
$month = date("Y", strtotime($eventdate)).'-'.date("m", strtotime($eventdate));
$monthname = date("F", strtotime($eventdate));
?>
Kick out the month name once if posts exist in that date and manipulate for output.
<li>
<a href="https://wordpress.stackexchange.com/questions/64362/<?php echo home_url("https://wordpress.stackexchange.com/" ); ?>whats-on-page/shows-by-month/?startdate=<?php echo($month); ?>-01&enddate=<?php echo($month); ?>-31&monthname=<?php echo ($monthname); ?>">
<?php echo ($monthname); ?>
</a>
</li>
<?php } ?>
Output the html so we have a li and link – link goes to a page using a custom page template which pulls the parameters passed in the URL into a meta query like below:
$start = $_GET["startdate"];
$end = $_GET["enddate"];
$monthname = $_GET["monthname"];
// gets info from URL
query_posts(array(
'post_type' => 'events', //query “events”
'posts_per_page' => 10,
'paged' => $paged,
'meta_key' => 'event_date',
'orderby' => 'meta_value',
'order' => 'ASC', //sort in ascending order
'meta_query' => array(
array(
'key' => 'event_date',
'value' => array($start, $end),
'compare' => 'BETWEEN',
'type' => 'DATE'
)
) // meta query between dates
));
if (have_posts()) :
while (have_posts()) : the_post();
So now I have a dynamic listing in the sidebar to link to a custom page template which filters by month, effectively recreating the post archive effect using a custom date field.
Sure I could probably create some URL rewrites to make this work with pretty URLs too but thats for another day.