I am trying to create a query to pull future events only. It was working great until the client requested the ability to add date ranges--so the event will either have a start date only, OR a start date and an end date. I need to build a query that pulls events events that has a start date in the future OR an end date in the future. This does not work as expected and pulls all events; and the order of what's pulled seems random, despite setting orderby to meta_value. Any help would be much appreciated!
function get_upcoming_events($num) {
$today = gmdate('Y-m-d', time()-28800);
$args = array(
'meta_key' => 'event_date',
'order' => 'ASC',
'orderby' => 'meta_value',
'post_status' => 'publish',
'posts_per_page' => $num,
'post_type' => 'events',
'meta_query' => array(
'relation'=>'OR',
array(
'key' => 'event_date',
'type' => 'DATE',
'value' => $today,
'compare' => '>='
),
array(
'key' => 'end_date',
'type' => 'DATE',
'value' => $today,
'compare' => '>='
)
)
);
if ( isset( $data[ 'taxonomy' ]) ) {
$args[ 'tax_query' ] = array();
$args[ 'tax_query' ][0] = array(
'field' => 'slug',
'taxonomy' => 'event-type',
'terms' => 'general'
);
}
$myquery = new WP_Query( $args );
return $myquery;
}