I have been trying for hours, I don't get my query to work: display only posts (from custom post type) with a field (Advanced Custom Fields date picker) value that is more than today.
echo date('d-m-Y');
prints the same date format as the posts output the_field('datum_event');
: 06-01-2019
$args = array(
'post_type' => 'agenda',
'meta_query' => array(
array(
'key' => 'datum_event',
'value' => '06-01-2019',
'compare' => '>='
)
),
);
$loop = new WP_Query( $args );
What is missing?
I have been trying for hours, I don't get my query to work: display only posts (from custom post type) with a field (Advanced Custom Fields date picker) value that is more than today.
echo date('d-m-Y');
prints the same date format as the posts output the_field('datum_event');
: 06-01-2019
$args = array(
'post_type' => 'agenda',
'meta_query' => array(
array(
'key' => 'datum_event',
'value' => '06-01-2019',
'compare' => '>='
)
),
);
$loop = new WP_Query( $args );
What is missing?
What is missing? One tiny detail... And it's easy to overlook...
the_field('datum_event');
Prints the field using the format you've defined in field settings. But... It has nothing to do with how the value of that field is stored in DB. ACF uses YYYYMMDD
format when storing date values in DB. And WP_Query doesn't use field format, since it looks directly in DB.
So you have to use other/raw format in your WP_Query:
$args = array(
'post_type' => 'agenda',
'meta_query' => array(
array(
'key' => 'datum_event',
'value' => '20190106',
'compare' => '>='
)
),
);
$loop = new WP_Query( $args );
'type' => 'DATE',
to the most inner array – kero Commented Jan 6, 2019 at 14:27