I'm trying to write a meta query that looks for either events starting within the next year (event_start_date between now and 52 weeks), or events that are still going on (event_end_date between now and 52 weeks), and then sorts them together via the event_start_date into one query to make a chronological event list.
My code successfully queries both and returns the results, but doesn't sort them together. They display in the order below:
12th Sept
13th Sept
18th Sept
11th - 13th Sept (end date)
20th Sept
27th Sept
25th Sept
26th Sept
20th Sept
19th Sept
Here is my code:
$date_1 = date('Ymd', strtotime("now"));
$date_2 = date('Ymd', strtotime("52 weeks"));
$args = array(
'post_type' => 'event',
'order' => 'ASC',
'meta_key' => 'event_start_date',
'posts_per_page' => 10,
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'event_start_date',
'value' => array( $date_1, $date_2 ),
'type' => 'numeric',
'compare' => 'BETWEEN'
),
array(
'key' => 'event_end_date',
'value' => array( $date_1, $date_2 ),
'type' => 'numeric',
'compare' => 'BETWEEN'
),
),
'orderby' => 'meta_value_num'
);
$wp_query = new WP_Query( $args );
while( $wp_query->have_posts() ) {
$wp_query->the_post();
}
type
toDATE
?