I’m using a custom loop to display my events on a page, I get it fine ordering by the event start date using the below:
$args = array(
'post_type' => 'event',
'order' => 'ASC',
'orderby' => 'meta_value',
'meta_key' => '_event_start_date');
$loop = new WP_Query( $args );
But the meta_key option only allows one value. How to use two values (_event_start_date
and _event_start_time
)?
You have to use meta_query at add your meta keys as everyone said, but also you have to customize order by function.
And put this on your functions.php
You can read more at http://dotnordic.se/sorting-wordpress-posts-by-several-numeric-custom-fields/
This is something that WordPress added support for in 4.2: https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-orderby-and-meta_query/
In your case you'll probably want to do something like this:
You can order on one key, of multiple. Like so:
The key here is that
meta_key
specifies which key we're ordering by, of the ones we use to grab our records withmeta_query
.From WP_Query documentation, use
meta_query
and fill up with an array of meta key/values: