Created
November 14, 2016 16:12
-
-
Save palicko/3ad57429ef9ae196bebd244b235dc69f to your computer and use it in GitHub Desktop.
Order by two meta values using meta_query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$meta_query = array( | |
'relation' => 'OR', | |
'featured' => array( // give the first meta key array an array key | |
'key' => 'is_featured', | |
'compare' => 'EXISTS', | |
'type' => 'NUMERIC' | |
), | |
'delivery_date' => array( // give the second meta key array an array key | |
'key' => 'to_be_delivered', | |
'compare' => 'EXISTS', | |
'type' => 'NUMERIC', | |
), | |
); | |
// order by using the meta array keys to reference them | |
// first order by 'delivery_date' value, then order by 'featured' value | |
$orderby = array( | |
'delivery_date' => 'DESC', | |
'featured' => 'DESC', | |
); | |
$query->set( 'meta_query', $meta_query ); | |
$query->set( 'orderby', $orderby ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment