Im trying to order my posts with some conditionals.
What i need: Filter posts with highlight = 1 then i have another field called ‘class_situation’ that have many values options that need to be ordered by its value.
Here’s what i got so far:
$query->set('meta_query', array(
'relation' => 'OR',
'destaque_clause' => array(
'key' => 'destaque',
'value' => '1',
),
'class_situation_clause' => array(
'relation' => 'AND',
array(
'key' => 'class_situation',
'value' => array('Inscrições Abertas / Confirmado', 'Inscrições Abertas', 'Inscrições Encerradas / Não Confirmado', 'Inscrições Encerradas / Confirmado'),
'compare' => 'IN'
),
array(
'key' => 'destaque',
'compare' => 'NOT EXISTS'
)
)
));
$query->set('orderby', array(
'highlight' => 'ASC',
'class_situation_clause' => 'ASC',
),
If i set the orderby for the ‘highlight’ field its shows the highlighted posts first but the remaning posts are ordered by title. If i change the orderby for the ‘class_situation’ field, its sort correctly but dont shows the highlighted posts at first place. Combinining the two orderby only works for ‘highlight’. What im doing wrong?
Ighor Gonçalves is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.