I see no way to do this with one WP_Query , since meta_query does not allow you that much flexibility, although you can make three different queries and then combine them (untested code):
// Get ongoing events $ongoing = new WP_Query(array( 'post_type' => 'event', 'meta_key' => 'date_from', 'orderby' => 'meta_value', 'order' => 'ASC', 'meta_query' => array( 'relation' => 'AND', array( 'key' => 'date_from', 'value' => date('Ym-d'), 'compare' => '<=', 'type' => 'DATE' ), array( 'key' => 'date_to', 'value' => date('Ym-d'), 'compare' => '>=', 'type' => 'DATE' ) ) )); foreach($ongoing as $key => $ongoing_post) { $ongoing_post->event_status = 'ongoing'; $ongoing[$key] = $ongoing_post; } // Get upcoming events $upcoming = new WP_Query(array( 'post_type' => 'event', 'meta_key' => 'date_from', 'orderby' => 'meta_value', 'order' => 'ASC', 'meta_query' => array( array( 'key' => 'date_from', 'value' => date('Ym-d'), 'compare' => '>', 'type' => 'DATE' ) ) )); foreach($upcoming as $key => $upcoming_post) { $upcoming_post->event_status = 'upcoming'; $upcoming[$key] = $upcoming_post; } // Get past events $past = new WP_Query(array( 'post_type' => 'event', 'meta_key' => 'date_from', 'orderby' => 'meta_value', 'order' => 'DESC', 'meta_query' => array( array( 'key' => 'date_to', 'value' => date('Ym-d'), 'compare' => '<', 'type' => 'DATE' ) ) )); foreach($past as $key => $past_post) { $past_post->past_status = 'past'; $past[$key] = $past_post; } // Merge'em all $events = array_merge($ongoing, $upcoming, $past);
The point is to use meta_query to compare metadata values ββwith the actual date (you can change the date format depending on how they are stored in the date_from and date_to ), and do a short cycle immediately after adding the property to all post objects with the correct event_status , with which you can work with when displaying messages.
There may be a smart way to achieve this through WP_Query filters , but this will require a more detailed study inside the WP_Query source code as it really is not documented inside the code.