我这里有完全相同的问题,只是我在查询中使用了标准的post类型(post)和一个类别。除排序顺序外,所有操作都正常。
$d = date("Y-m-d");
$args = array(
\'post_type\' => \'post\',
\'category_name\' => \'events\',
\'post_status\' => \'publish,draft,pending,future,private\', // just for me
\'meta_key\' => \'event_start\',
\'orderby\' => \'meta_value_num\',
\'order\' => \'ASC\',
\'posts_per_page\' => -1,
\'meta_query\' => array(
array(
\'key\' => \'event_start\',
\'value\' => $d,
\'type\' => \'date\',
\'compare\' => \'>\'
)
)
);
但我的帖子仍然是通过字符串比较来排序的。我做错了什么?
经过一些尝试和错误,我发现我应该使用“meta\\u value”而不是“meta\\u num”:
$d = date("Y-m-d");
$args = array(
\'post_type\' => \'post\',
\'category_name\' => \'events\',
\'post_status\' => \'publish,draft,pending,future,private\',
\'meta_key\' => \'event_start\',
\'orderby\' => \'meta_value\',
\'order\' => \'ASC\',
\'posts_per_page\' => -1,
\'meta_query\' => array(
array(
\'key\' => \'event_start\',
\'value\' => $d,
\'type\' => \'date\',
\'compare\' => \'>\'
)
)
);