Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WP_Query Ordered By Multiple Meta Keys
<?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
You can’t perform that action at this time.