3

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.

3
  • How is your event_start_date stored (YYYY-MMM-DD, int, ...)? Have a look at the WP_Query docs on Custom Field Parameters.
    – Pat J
    Oct 30, 2014 at 16:46
  • It was a premade thing, it is stored as a longtext type. the actual date is stored like this: 2014-11-14 20:00
    – Chrizlee
    Oct 30, 2014 at 17:47
  • 1
    Longtext or not, what is the format of the date string? See the first part of the following answer: wordpress.stackexchange.com/a/124163/21376
    – s_ha_dum
    Oct 30, 2014 at 17:49

2 Answers 2

4

adding the following arguments did the trick

'meta_value' => date('Y-m-d h:i'),
      'meta_compare' => '>',
1
  • Glad to hear you got it sorted out. Please remember to mark your answer Accepted once you're able to (it's a 48-hour wait).
    – Pat J
    Oct 30, 2014 at 19:08
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.