当您使用\'meta_key\' => \'Start_Hour Start_Minute\'
然后查询查找具有名为Start_Hour Start_Minute
所以这就是为什么它不适合你。
但有一种方法可以通过使用posts_orderby
过滤器挂钩,因此首先创建一个函数,该函数将添加orderby字段,如下所示:
function orderbyreplace($orderby ) {
global $wpdb;
return str_replace($wpdb->prefix.\'postmeta.meta_value\', \'mt1.meta_value, mt2.meta_value ASC\', $orderby);
}
然后将参数设置为:
$args = array(
\'post_type\'=>\'Events\',
\'orderby\' => \'meta_value\',
\'meta_key\' => \'Start_Hour\',
\'meta_query\' => array(
array(
\'key\' => \'Start_Hour\',
\'value\' => \'0\',
\'type\' => \'NUMERIC\',
\'compare\' => \'!=\'
),
array(
\'key\' => \'Start_Minute\',
\'value\' => \'0\',
\'type\' => \'NUMERIC\',
\'compare\' => \'!=\'
)
)
);
查看我如何使用meta\\u查询,该查询将连接两个自定义字段,剩下的就是在查询之前挂接orderbyreplace函数,以便:
add_filter(\'posts_orderby\',\'orderbyreplace\');
$loop = new WP_Query( $args );
remove_filter(\'posts_orderby\',\'orderbyreplace\');