Below is the code I'm using to query multi-day events. The problem I'm having is that I can either sort by the start date (evstart_date) OR I can do a combined query against start date and end date (evend_date). But I cannot do both the combined query AND sort. The code below gets the query right (continues to display multi-day events that started in the past but have not yet ended), but the sort is broken (reverts to default sort by post date).
I've tried several variations, but have been unable to find a solution.
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$today = date('Y-m-d', strtotime('-6 hours'));
$upcomingevents = new WP_Query(array(
'post_type' => 'events',
'posts_per_page' => 6,
'paged' => $paged,
'meta_query'=>array(
'relation'=>'OR',
array(
'key' => 'evstart_date',
'value' => $today,
'compare' => '>=',
'type' => 'CHAR'
),
array(
'key' => 'evend_date',
'value' => $today,
'compare' => '>=',
'type' => 'CHAR'
)
),
'meta_key' => 'evstart_date',
'orderby' => 'meta_value',
'order' => 'ASC'
));
?>
date
, notchar
. otherwise, post the SQL generated by this query, perhaps you can't sort on a key used in anOR
relation?