我有一个自定义帖子类型,根据自定义发布日期(事件日期)显示但现在我无法使用内置的WordPress日程安排,因为帖子显示与帖子中提供的自定义元日期相关。 / p>
有没有办法在我的数组中添加一个参数来检查发布日期,以便在发布日期过后它只显示自定义帖子?
这是我当前正确执行的代码
$today = date('Y-m-d');
$args = array(
'post' => 'ID',
'post_type' => 'foodswaps',
'posts_per_page' => 3,
'meta_key' => '00.event-date',
'meta_value' => $today,
'meta_compare' => '>=',
'orderby' => 'meta_value',
'order' => 'ASC'
);
我花了最后一天寻找答案,但没有发现任何事情或类似情况,所以任何指针和定向推动都会受到赞赏!
答案 0 :(得分:2)
尝试添加:
'post_status'=> '发布',
E.g。
$today = date('Y-m-d');
$args = array(
'post' => 'ID',
'post_type' => 'foodswaps',
'posts_per_page' => 3,
'post_status' => 'publish', // <-----------
'meta_key' => '00.event-date',
'meta_value' => $today,
'meta_compare' => '>=',
'orderby' => 'meta_value',
'order' => 'ASC'
);
然后应该只显示已发布状态的帖子。