我想按2个自定义字段和字母排序,这是我的代码
\'meta_query\' => array(
array(
\'relation\' => \'AND\',
\'awards\' => array(
\'key\' => \'awards\',
\'compare\' => \'EXISTS\',
),
\'points\' => array(
\'key\' => \'points\',
\'compare\' => \'EXISTS\',
),
),
),
\'orderby\' => array(
\'awards\' => \'desc\',
\'points\' => \'desc\',
),
因此,如果奖励相同,则按分数排序,但如果分数相同,则按字母顺序排序。
SO网友:Max Yudin
子句周围包含了不必要的数组。正确的代码为
\'meta_query\' => array(
\'relation\' => \'AND\',
\'awards_clause\' => array( // clause
\'key\' => \'awards\',
\'compare\' => \'EXISTS\',
),
\'points_clause\' => array( // clause
\'key\' => \'points\',
\'compare\' => \'EXISTS\',
),
),
\'orderby\' => array(
\'awards_clause\' => \'DESC\',
\'points_clause\' => \'DESC\',
),