wordpress - How to order by custom post type by two custom field -


here meta query filter properties property_type , bedrooms order price in desc order.

$properties = array(         'post_type' => 'soto_property',         'paged'=>$paged,         'posts_per_page' => 6,        'orderby'    => 'meta_value_num',         'meta_key'  => 'price',       );      /*check price range */     if (!empty($_get['price_range'])) {         $lowestprice=get_post_meta($_get['price_range'],"lowest_price",true);         $maximumprice=get_post_meta($_get['price_range'],"maximum_price",true);         $properties['meta_query'][] = array(             'key' => 'price',             'value' =>  array($lowestprice, $maximumprice),             'type' => 'numeric',             'compare' => 'between',         );     }     else     {         $properties['meta_query'][] = array(             'key' => 'price',             'compare' => 'exists'         );     }        /*check bedrooms range */    if (!empty($_get['bedrooms'])) {         $beds_value=get_post_meta($_get['bedrooms'],"beds_value",true);         if($beds_value)         {             $properties['meta_query'][] = array(             'key' => 'dorm_room',             'value' =>  $beds_value,             'type' => 'numeric',             'compare' => '>='             );          }     }  function orderbyreplace($orderby ) {          global $wpdb;                  return ('mt1.meta_value desc, mt2.meta_value asc');             }         add_filter('posts_orderby','orderbyreplace');          query_posts($properties);         remove_filter('posts_orderby','orderbyreplace'); 

it works correctly want order properties bedrooms.

for example if bedroom value selected "2" properties filtered have bedrooms value greater 2.

i want order properties first properties bedrooms value 2 filtered in price order(desc) properties bedrooms value 3 filtered in price order(desc) , bedrooms value 4,5 , 6.

how that?

as far know multiple sorting meta_values not available in wp_query.

however can use posts_orderby filter , here it's example


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -