HI,
i am trying to show posts sorted by double meta_key.
I have to show rooms sorted first by state (first the free ones and then the occupied ones, there are only two states) and then by the date on which these rooms are free.
This is my code: for now I can make sure that the free rooms are shown first and then the occupied ones, but I can’t sort them by date.
$args = array(
'post_type' => 'listing',
'post_status' => 'publish',
'posts_per_page' => -1,
'meta_key' => 'repeater_letti_0_stato',
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'repeater_letti_0_stato',
),
array(
'key' => 'repeater_letti_0_libero_da',
'order' => 'DESC',
),
),
);
Can someone help me? Thanks
WP_Query() search for “_clause” and you will find an example of ordering by multiple meta keys. It is currently the 10th code example in this section https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters