I have the following code that filters and only shows results with fields containing “Apartment” + “3 bedrooms”. It works great.
<?php
$args = array(
'post_type' => 'propriedades',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'tipo_de_propriedade',
'value' => 'Apartamento',
'compare' => '='
),
array(
'key' => 'dormitorios_do_imóvel',
'value' => '3 Dormitórios',
'compare' => '='
)
)
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<?php echo '<div class="post">'; ?>
Look at the result in the link
http://www.sidiimoveis.com.br/site/apartamento-03-dormitorios/
How do I sort results by the highest value to the lowest value? In the case it would be the price: R$ 1.050.000,00 , R$ 800.000,00, R$ 50.000,00 etc…
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' => '='
)
)
);
'orderby' => 'meta_value_num',
I switched to
'orderby' => 'meta_value meta_value_num',
removed from the register the dollar, let alone the numbers
It worked perfectly! Thank you very much John Huebner. The best support!
I’m having trouble on the order of some values is to help me again?
Hey there, I didn’t see the new message. Usually after you mark a question as solved the best thing to do is start a new topic.