wordpress 元查询子句传递的WP_Query顺序?

6jjcrrmo  于 2022-11-22  发布在  WordPress
关注(0)|答案(1)|浏览(125)

当使用带有多个子句的 meta查询时,使用“OR”关系时,我如何根据通过的子句对结果进行排序?例如,我希望最后返回“Completed”状态,但还有其他状态未显示。

$args = [
   ...
   'meta_query' => [
      'relation' => 'OR',
      'clause_one' => [
         'key' => 'status',
         'compare' => 'IN',
         'value' => ['Registered', 'Pretested']
      ],
      'clause_two' => [
         'key' => 'status',
         'value' => 'Completed',
      ]
   ],
]
66bbxpm5

66bbxpm51#

试试这个:-

$args = [
   ...
   'meta_query' => [
      'relation' => 'OR',
      'clause_one' => [
         'key' => 'status',
         'compare' => 'IN',
         'value' => ['Registered', 'Pretested']
      ],
      'clause_two' => [
         'key' => 'status',
         'value' => 'Completed',
      ]
   ],
  
'orderby' => [
        'clause_one' => 'DESC',
        'clause_two' => 'ASC',
    ]
]

相关问题