定义必须设置的填充,并将允许的状态列为一个数组。
之后,将人口纳入orderby
并对其进行排序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\',
),
) );
将两种不同的条件与
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\',
),
) );