Reputation: 830
I am using this WP query to fetch just the future events but the query returns all the events, even the past ones. What am I doing wrong? The date format is the same (j F Y) of the one coming from the ACF custom field and the tax_query is working because only the events belonging to the specified location are fetched (location_categories).
$events = array(
'post_type' => 'event',
'post_status'=>'publish',
'meta_key' => 'event_start_date',
'orderby' => 'meta_value',
'order' => 'DESC',
'posts_per_page'=>'6',
'paged' => $paged,
'tax_query' => array(
array(
'taxonomy' => 'location_categories',
'field' => 'term_id',
'terms' => get_field('choose_event_location',$page_id)
)
),
'meta_query' => array(
array(
'key' => 'event_start_date',
'value' => date("j F Y"),
'compare' => '>=',
'type' => 'DATE'
)
)
);
$loop = new WP_Query($events);
Upvotes: 0
Views: 211
Reputation: 11282
ACF save date as 'Ymd'. try date("Ymd")
This is how ACF saves date.
Check the below code.
$events = array(
'post_type' => 'event',
'post_status' =>'publish',
'meta_key' => 'event_start_date',
'orderby' => 'meta_value',
'order' => 'DESC',
'posts_per_page' =>'6',
'paged' => $paged,
'tax_query' => array(
array(
'taxonomy' => 'location_categories',
'field' => 'term_id',
'terms' => get_field('choose_event_location',$page_id)
)
),
'meta_query' => array(
array(
'key' => 'event_start_date',
'value' => date("Ymd"),
'compare' => '>=',
'type' => 'DATE'
)
)
);
$loop = new WP_Query($events);
Upvotes: 1