Wordpress - Multiple orderby values in WP_Query
@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 here for more details : https://make.wordpress.org/core/2014/08/29/a-more-powerful-order-by-in-wordpress-4-0/
$query=new WP_Query(array(
'post_type'=>'wpcontactus',
'nopaging'=>true,
'post_status'=>array('publish', 'pending', 'future'),
'meta_query'=>array(
array('key'=>'wcu_dept','value'=>$dept_id, 'compare'=>'='),
),
'meta_key'=>'wcu_firstname',
'orderby'=>'menu_order wcu_firstname',
'order'=>'ASC'
));
By using what @kaiser suggested and the meta_query
option, I was able to get the query I was looking for.