admin管理员组文章数量:1321245
I want to only get posts with current or future dates, to show upcoming events.
Current arguments:
$args = array(
'post_type' => 'event',
'meta_key' => 'event_start_date',
'orderby' => 'meta_value',
'order' => 'ASC'
);
This returns all the posts, including past events.
I read about post_status
but it did not seem to work. I tried 'post_status' => 'future'
without success.
I want to only get posts with current or future dates, to show upcoming events.
Current arguments:
$args = array(
'post_type' => 'event',
'meta_key' => 'event_start_date',
'orderby' => 'meta_value',
'order' => 'ASC'
);
This returns all the posts, including past events.
I read about post_status
but it did not seem to work. I tried 'post_status' => 'future'
without success.
2 Answers
Reset to default 4adding the following arguments did the trick
'meta_value' => date('Y-m-d h:i'),
'meta_compare' => '>',
Adding 'post_status' => array('publish', 'future')
to your $args
will show only future published posts.
$args = array(
'post_type' => 'event',
'meta_key' => 'event_start_date',
'orderby' => 'meta_value',
'order' => 'ASC',
'post_status' => array('publish', 'future')
);
get_posts( $args );
本文标签: How to query posts with current or future date only
版权声明:本文标题:How to query posts with current or future date only 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742033097a2416816.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
event_start_date
stored (YYYY-MMM-DD
,int
, ...)? Have a look at theWP_Query
docs on Custom Field Parameters. – Pat J Commented Oct 30, 2014 at 16:46