• Hi there,

    I am trying to get posts ordered by meta values. What I need is to get events between today and today+15 days order by dates.
    Dates are stored in meta as timestamps.

    This is the code I am having at the moment but it keeps me getting posts order by id..

    <?php
            setlocale(LC_ALL, "fr_FR.UTF-8");
            $now = time();
            $in15days = time() + 24*3600*15;
            $args = array(
                'post_type'  =>  'events',
                'posts_per_page' => 10,
                'meta_key'   =>  'eventtimestamp',
                'order_by'   =>  'meta_value_num',
                'order'      => 'ASC',
                'meta_query'  => array(
                                    array(
                                        'key'     =>  'eventtimestamp',
                                        'value'   =>  array($now, $in15days),
                                        'compare' =>  'BETWEEN',
                                        'type'    =>  'NUMERIC',
                                    )
                                  )
              );
    $the_query = new WP_Query( $args ); ?>

The topic ‘WordPress Query Order by meta_key’ is closed to new replies.