I want to orderby post by 2 custom fields and alphabetical here is my code
'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 if the awards are same so it will order by points but if the points will same also so it will orber by alphabetical.
I want to orderby post by 2 custom fields and alphabetical here is my code
'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 if the awards are same so it will order by points but if the points will same also so it will orber by alphabetical.
You've got the unnecessary array involved around clauses. The correct code is
'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',
),