How to use ACF date fields with WP_Query
Let’s say you have an “event” custom post type, and you’ve added an ACF date field to it.
Now you want to display events whose date is in the future i.e. forthcoming events.
$date_now = date('Y-m-d H:i:s');
$q = new WP_Query([
'post_type' => 'event',
'posts_per_page' => 3,
'post_status' => 'publish',
'meta_query' => [
'primary_date_clause' => [
'key' => 'primary_date',
'compare' => '>=',
'value' => $date_now,
'type' => 'DATETIME',
]
],
'orderby' => 'primary_date_clause',
'order' => 'ASC'
]);
This example assumes your ACF field name is primary_date.
Because we have named the primary_date_clause within the meta query, we can use that to order the results.