我创建了一个名为event的CPT,并希望根据它的发布日期进行查询以显示下一个将来的事件。
这是WP_Query
参数:
$today = getdate();
$args = array(
\'post_status\' => array(\'publish\', \'future\'),
\'post_type\' => \'event\',
\'orderby\' => \'date\',
\'order\' => \'ASC\',
\'posts_per_page\' => 1,
\'date_query\' =>
array(
array(
\'year\' => $today[\'year\'],
\'compare\' => \'>=\',
),
array(
\'month\' => $today[\'mon\'],
\'compare\' => \'>=\',
),
array(
\'day\' => $today[\'mday\'],
\'compare\' => \'>=\',
)
)
);
当当月有活动时,工作正常。但现在,下一个活动是在四月,脚本没有显示任何内容。
SOLUTION
$args = array(
\'post_status\' => array(\'publish\', \'future\'),
\'post_type\' => \'event\',
\'orderby\' => \'date\',
\'order\' => \'ASC\',
\'posts_per_page\' => 1,
\'date_query\' =>
array(
\'after\' => \'today\'
)
);