Created
November 18, 2015 12:48
-
-
Save wpmark/217422b4210fdd8e3c46 to your computer and use it in GitHub Desktop.
WP_Query Ordered By Multiple Meta Keys
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
<?php | |
/* build a new wp_query */ | |
$classes = new WP_Query( | |
array( | |
'post_type' => 'wpmark_class_time', // post type to query | |
'posts_per_page' => -1, // get all the posts not limited | |
'meta_query' => array( | |
'relation' => 'AND', | |
'day' => array( // give the first meta key array an array key | |
'key' => '_wpmark_day', | |
'compare' => 'EXISTS', | |
'type' => 'NUMERIC' | |
), | |
'location' => array( | |
'key' => '_wpmark_location', | |
'value' => $post->ID, | |
'compare' => 'EXISTS' | |
), | |
'start_time' => array( | |
'key' => '_wpmark_start_time', | |
'compare' => 'EXISTS', | |
'type' => 'NUMERIC', | |
) | |
), | |
// order by using the meta array keys to reference them | |
'orderby' => array( | |
'day' => 'ASC', | |
'start_time' => 'ASC' | |
), | |
'fields' => 'ids' | |
) | |
); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment