WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to come up with a query to sort by multiple orderby values. Here's what I have so far:

    $query=new WP_Query(array(
            'post_status'=>array('publish', 'pending', 'future'),

I'm trying to query a custom post type, and within that post type, query a meta value.

Then, I'd like to first sort by menu_order ascending, then by a custom meta value wcu_lastname ascending. However, the orderby value didn't seem to be able to take an array.

How can I order the query using multiple orderby values?

share|improve this question
If I'm not wrong, simply add them space separated. – kaiser Sep 20 '12 at 16:05
up vote 3 down vote accepted
$query=new WP_Query(array(
                'post_status'=>array('publish', 'pending', 'future'),
                                array('key'=>'wcu_dept','value'=>$dept_id, 'compare'=>'='),
                'orderby'=>'menu_order wcu_firstname',

By using what @kaiser suggested and the meta_query option, I was able to get the query I was looking for.

share|improve this answer
how can we put multiple order value for the fields? For ex: ASC for menu_order, DESC for date – Musa Mar 20 '14 at 11:44

@Musa how can we put multiple order value for the fields? I was wondering the same question and I found this :

In 4.0, you can now pass an array to WP_Query as the value for orderby. The syntax looks like:

$q = new WP_Query( array( 'orderby' => array( 'title' => 'DESC', 'menu_order' => 'ASC' ) ) );

Have a look where for more details : https://make.wordpress.org/core/2014/08/29/a-more-powerful-order-by-in-wordpress-4-0/

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.