Define that a population has to be set, and make a list of allowed states as an array.
Afterwards, take population into the orderby
and sort it DESC
.
$q = new WP_Query( array(
'meta_query' => array(
'relation' => 'AND',
'state_clause' => array(
'key' => 'state',
'value' => array( 'Wisconsin', 'California' ), //allowed values
'compare' => 'IN' // state must be in array above
),
'population_clause' => array(
'key' => 'population',
'compare' => 'EXISTS',
),
),
'orderby' => array(
'population_clause' => 'DESC',
),
) );
To have two different condition combined with an OR
:
$q = new WP_Query( array(
'meta_query' => array(
'relation' => 'OR',
'state_clause' => array(
'key' => 'state',
'value' => array( 'Wisconsin' ), // allowed values
'compare' => 'IN' // state must be in array above
),
'state_clause' => array(
'key' => 'timezone',
'value' => 'central',
'compare' => '='
),
'population_clause' => array(
'key' => 'population',
'compare' => 'EXISTS',
),
),
'orderby' => array(
'population_clause' => 'DESC',
),
) );