我正在尝试使用ACF DateTime选择器字段提取WordPress中即将发生的事件的列表。
我认为应该是一套相对简单的$args
令我困惑,为什么它不起作用:
$args = [
"post_type" => "event",
"post_status" => "publish",
"posts_per_page" => 3,
"order" => "ASC",
"orderby" => "meta_value",
"cat" => implode(',', $category),
"meta_query" => [
[
"key" => "event_start_date_and_time",
"compare" => ">=",
"value" => date('U'),
"type" => "DATETIME"
]
],
"meta_key" => "event_start_date_and_time",
"meta_type" => "DATE"
];
这是带通事件,但并非所有事件都按开始日期时间的ASC顺序排列。
我缺少明显的东西吗?
文献资料https://www.advancedcustomfields.com/resources/date-time-picker/
数据库值ACF DateTime Picker字段将日期存储在数据库中,如下所示
2018-07-21 15:00:00
答案 0 :(得分:0)
以下代码正在运行其经过测试的代码。
$posts = array(
"post_type" => "product",
"post_status" => "publish",
"posts_per_page" => 3,
"order" => "ASC",
"orderby" => "meta_value",
"cat" => implode(',', $category),
"meta_query" => (
array (
"key" => "evntdate",
"compare" => ">=",
"value" => date('U'),
"type" => "DATETIME"
)
),
"meta_key" => "evntdate",
"meta_type" => "DATETIME"
);
$posts=get_posts($posts);