order by meta query wordpress

Solutions on MaxInterview for order by meta query wordpress by the best coders in the world

showing results for - "order by meta query wordpress"
Samuel
22 Jan 2018
1$q = new WP_Query( 
2    array(
3        'meta_key' => 'population', //setting the meta_key which will be used to order
4        'orderby' => 'meta_value', //if the meta_key (population) is numeric use meta_value_num instead
5        'order' => 'DESC', //setting order direction
6        'meta_query' => array(
7            'relation' => 'AND', //setting relation between queries group
8            array(
9                'relation' => 'OR', //setting relation between this inside query
10                array(
11                    'key' => 'state',
12                    'value' => 'Wisconsin',
13                ),
14                array(
15                    'key' => 'timezone',
16                    'value' => 'central',
17                )
18            ),
19            array(
20                'key' => 'city',
21                'compare' => 'EXISTS',
22            )
23        )
24    )           
25);
26