Skip to content

Instantly share code, notes, and snippets.

@michaelschofield
Last active August 29, 2015 14:18
Show Gist options
  • Save michaelschofield/12a789a800b7efd0fa46 to your computer and use it in GitHub Desktop.
Save michaelschofield/12a789a800b7efd0fa46 to your computer and use it in GitHub Desktop.
function advwp_edit_event_order( $orderby ) {
// First sort by start date, but then internally sort
// by start time - starting with the earliest.
return 'mt1.meta_value, mt2.meta_value ASC';
}
$args = array(
// fetch only "events""
'post_type' => 'event',
// we can't orderby a meta_value if the
// key isn't present ... - even if we
// aren't actually using 'orderby' directly
// in the query.
'meta_key' => 'advwp_start_date',
// We define multiple keys using 'meta_query'
'meta_query' => array(
// the first key, or mt1
array(
'key' => 'advwp_start_date'
),
// the second key, or mt2
array(
'key' => 'advwp_start_time'
)
)
);
add_filter( 'posts_orderby', 'advwp_edit_event_order' );
$the_query = new WP_Query( $args );
remove_filter( 'posts_orderby', 'advwp_edit_event_order' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment