I am trying to order custom fields by state and city. This is for a WordPress website and I am using ACF custom fields.
Find my unsuccessful meta_query below.
$hotel = new WP_Query( array(
'post_type' => 'hotel',
'meta_query' => array(
'relation' => 'AND',
'country' => array(
'meta_key' => 'hotel_address_country',
'compare' => 'EXISTS',
),
'city' => array(
'meta_key' => 'hotel_address_city_state',
'compare' => 'EXISTS',
),
),
'orderby' => array(
'country' => 'DESC',
'city' => 'ASC',
),
'numberposts' => -1,
'post_status' => 'publish',
'public' => 'true',
'posts_per_page' => '500',
) );
I haven't had a chance to test. But I got this feedback and think it will work in case anyone else is looking for the solution...
$hotel = new WP_Query( array( 'post_type' => 'hotel', 'numberposts' => -1, 'meta_query' => array( 'relation' => 'AND', 'country_clause' => array( 'key' => 'hotel_country', 'compare' => 'EXISTS', ), 'city_clause' => array( 'key' => 'hotel_city', 'compare' => 'EXISTS', ),
);