我有一个自定义post类型“events”的元查询。其开始日期存储为以下格式的元字段:
2016-02-05 19:00:00
以下是我的查询参数:
$args = array(
"posts_per_page" => 12,
"paged" => $paged,
"post_type" => array(
"event",
"post"
) ,
"post_status" => "publish",
"meta_key" => "_thumbnail_id",
\'meta_query\' => array(
\'relation\' => \'OR\',
array(
\'key\' => \'event_start\',
\'value\' => date("Y-m-d H:i:s") ,
\'compare\' => \'>=\',
\'type\' => \'DATE\'
) ,
array(
\'key\' => \'event_start\',
\'compare\' => \'NOT EXISTS\'
)
) ,
array(
\'key\' => \'foreign_language\',
\'value\' => 0
) ,
array(
\'key\' => \'hide_from_most_recent\',
\'value\' => 0
)
);
问题:当前日期+时间是:
2016-02-05 12:29:16
此查询应返回具有此元值的帖子:2016-02-05 19:00:00
昨天(在此日期前一天)它起了作用。今天它没有。意思是:如果一天都是一样的,但小时和分钟都比现在大,那么它就不能正常工作。似乎,小时、分钟和秒都被忽视了。我想问题是因为我把时间和时间混在一起了;日期
对吗?查询应该是什么样子的,它是如何工作的?
非常感谢
最合适的回答,由SO网友:user998163 整理而成
找到错误:
$args = array(
"posts_per_page" => 12,
"paged" => $paged,
"post_type" => array(
"event",
"post"
) ,
"post_status" => "publish",
"meta_key" => "_thumbnail_id",
\'meta_query\' => array(
\'relation\' => \'OR\',
array(
\'key\' => \'event_start\',
\'value\' => date("Y-m-d H:i:s") ,
\'compare\' => \'>=\',
\'type\' => \'DATETIME\'
) ,
array(
\'key\' => \'event_start\',
\'compare\' => \'NOT EXISTS\'
)
) ,
array(
\'key\' => \'foreign_language\',
\'value\' => 0
) ,
array(
\'key\' => \'hide_from_most_recent\',
\'value\' => 0
)
);
一定是这样
DATETIME
而不是
DATE
作为比较类型。