正如我在评论中已经指出的,您所需要做的就是更改orderby
参数,以便meta_prio
是第一项,后跟meta_start
. 所以你的orderby
应如下所示:
// This array forms an ORDER BY clause with each array item being a column that
// MySQL use when sorting the posts/results.
\'orderby\' => array(
// This is the first column, which has the highest priority and sorts by the
// meta high_prio.
\'meta_prio\' => \'DESC\',
// This is the second column, which sorts by the meta date_start, after MySQL
// sort the results by the meta high_prio.
\'meta_start\' => \'ASC\',
)
因此,在上面的示例中,生成
ORDER BY
子句看起来像
ORDER BY <meta_prio column> DESC, <meta_start column> ASC
MySQL将首先按照
high_prio
然后对
sorted 结果由
date_start
元。
请记住,在orderby
必须与meta_query
, 如果要按中的元查询子句对结果进行排序meta_query
大堆此外,请确保设置了正确的type
在元查询子句中;e、 g.如果值是如下日期2020-03-12 09:30
, 然后将类型设置为DATETIME
(即。\'type\' => \'DATETIME\'
):
\'meta_query\' => array(
\'relation\' => \'OR\',
\'meta_start\' => array(
\'key\' => \'date_start\',
\'type\' => \'DATETIME\',
),
\'meta_prio\' => array(
\'key\' => \'high_prio\',
\'type\' => \'NUMERIC\',
)
),
// Make sure the array keys match those in the above meta_query array.
\'orderby\' => array(
\'meta_prio\' => \'DESC\',
\'meta_start\' => \'ASC\',
),