Last active
August 29, 2015 14:18
-
-
Save michaelschofield/12a789a800b7efd0fa46 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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