Support

Account

Home Forums General Issues How to order by date field Reply To: How to order by date field

  • After looking on the internet for the last 4 hours, I finally figure it out. You have to put the orderby metadata first, then add a meta_query array to filter through the posts.

    $args = array (
        'post_type' => 'route',
            'meta_key' => 'trip_start_date',
            'orderby' => 'meta_value_num',
            'order' => 'ASC',
            'meta_query' => array(
                array(
                    'meta_key'  => 'route_status',
                    'compare'   => '=',
                    'value'     => 'not-yet-launched',
                ),
            ),
            'posts_per_page' => '9',
    );