I have the following code which loops through some custom post types and orders them two custom meta values - firstly by start date and then secondly by duration. This works fine - except for tours that don't have start dates assigned. These are output at the top of the list, and I'd like them to be at the bottom, so the user sees the items with start dates assigned first. Any ideas how to amend this query?

$tours = new WP_Query( array(
'post_type'         => 'tour',
'posts_per_page'    => -1,

'meta_query' => array(
    'relation' => 'AND',
    'start_date' => array(
        'key' => 'start_date',
    'duration' => array(
        'key' => 'duration',
        'type' => 'NUMERIC',
'orderby' => array( 
    'start_date' => 'ASC',
    'duration' => 'ASC',

) );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.