不幸的是,wordpress 不支持此功能,您必须在从数据库中获取它之后和循环之前自行对其进行排序。
Disclaimer note
This is extremely ugly by design, but this is Wordpress so you have to play with what you get, you can make it less ugly if you fallback to writing the SQL queries yourself, depends on performance in my opinion, as Wordpress can be a performance degrader beast if not handled properly you should consider making it with SQL queries instead.
// Fetch all posts - (1 SQL Query)
$query = new WP_Query(array(
'post_type' => 'my-cpt',
'order' => 'ASC',
'posts_per_page' => -1,
));
foreach ($query->posts as &$post) { // N queries as the number of posts you have - totally inefficient
$post->meta = get_post_meta($post->ID);
}
usort($query->posts, function($a, $b) {
$a_time = strtotime($a->meta['_start_hour'][0] . ':' . $a->meta['_start_minute'][0]);
$b_time = strtotime($b->meta['_start_hour'][0] . ':' . $b->meta['_start_minute'][0]);
if ($a_time > $b_time)
return 1;
else if ($a_time < $b_time)
return -1;
else
return 0;
}); // Sorting by date
... the_loop ...
note that this is totally untested so it should just give you pointers on hour should you do it, and again I say, you should refactor this to join the meta keys in advance, that way you can perhaps already sort it with the SQL instead of the PHP...