1

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.

0

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',
),

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.