Support

Account

Home Forums General Issues How do I sort results by the highest value to the lowest value? Reply To: How do I sort results by the highest value to the lowest value?

  • The easiest way is to add a meta_key and orderby to your args

    
    $args = array(
        'post_type' => 'propriedades',
        'meta_key' => 'price_field_name',
        'orderby' => 'meta_value_num',
        'order' => 'DESC',
        'meta_query' => array(
            'relation' => 'AND',
            array(
                'key' => 'tipo_de_propriedade',
                'value' => 'Apartamento',
                'compare' => '='
            ),
    
            array(
                'key' => 'dormitorios_do_imóvel',
                'value' => '3 Dormitórios',
                'compare' => '='
            )
    		
        )
    );