I've a custom post field called myplugin_date
the value in the database looks like 01.07.2019
. I'm trying to get all post where this value is before today. My query looks like this:
$query = new WP_Query([
'cat' => $category,
'order_by' => 'date',
'order' => 'asc',
'posts_per_page' => $displayCount,
'page' => $page,
'offset' => $offset,
'meta_query' => [
'key' => 'myplugin_date',
'value' => date("d.m.Y"),
'compare' => '<',
'type' => 'DATE',
],
]);
The problem is that I get also posts where the date defined in the custom field is after today. What is going wrong?
When you use meta_query you have to use two-dimensional array, like this:
$query = new WP_Query([
'cat' => $category,
'order_by' => 'date',
'order' => 'asc',
'posts_per_page' => $displayCount,
'page' => $page,
'offset' => $offset,
'meta_query' => [
[
'key' => 'myplugin_date',
'value' => date("d.m.Y"),
'compare' => '<',
'type' => 'DATE',
]
],
]);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.