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 );
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