Support

Account

Home Forums General Issues WordPress WP_Query query event post type for events after current time

Helping

WordPress WP_Query query event post type for events after current time

  • I don’t know why I can’t get this to work. So I want to get a list of events that are in the future. The event date is stored as a timestamp. I want to order them by the next event first and the next one after that etc.

    Here’s what I’m using but it’s not ordering by the timestamp and it’s even showing events that have passed.

        $args = array (
    	'post_type' => 'race', 
    	'posts_per_page' => -1,
    	'meta_key' => 'race_date',
    	'orderby' => 'meta_value',
    	'order' => 'ASC',
    	'meta_compare' => '>=',
    	'meta_value' => time()
        );

    So for example there’s an event with the timestamp 1540322400 and the time of testing it was 1552474027 so I don’t know why that event is being returned.

    Then for example an event with the timestamp 1556447400 is showing before in order of an event with the timestamp 1551813600.

    In this case I’m using Advanced Custom Fields date and time picker and storing it using a custom value U to store a timestamp.

    I’m not sure why I can’t get this to work.

  • What type of field is this.

    Date fields are stored as “Ymd”

    Date/time field are stored “Y-m-d H:i:s”

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.