WordPress.org

Ready to get started?Download WordPress

Forums

WP_Query - orderby meta_value_num with unix timestamps (1 post)

  1. wintermute77
    Member
    Posted 2 years ago #

    I'm using the code below to pull upcoming webcasts onto the homepage. It works fine, except for one anomaly - it's not ordering correctly by date.

    The dates are stored as a Unix timestamp, so comparing as number should - I'd have thought - be no problem. However, as an example, the three webcasts that the code below is pulling through at the moment have date values of:

    1337212800
    1335225600
    1338249600

    ... and that't the order they're displayed in. Even I can see that's not numerically ordered, and my maths is rubbish.

    So what's going on?

    $args = array(
    	'post_type'	=> 'webcast',
    	'meta_key'	=> 'webcast-date',
    	'meta_value'	=> array( time(), strtotime('+60 days') ),
    	'meta_type' 	=> 'numeric',
    	'meta_compare'	=> 'BETWEEN',
    	'orderby '	=> 'meta_value_num',
    	'order'		=> 'ASC'
    );
    $webcasts = new WP_Query($args);

Topic Closed

This topic has been closed to new replies.

About this Topic