Wordpress - Order by meta value num

Asked

Viewed 80 times

0

I’m cracking my head with a problem I’m having with Wordpress.

I’m using the ordination meta_value_num to sort from a meta_key that goes the value of some properties (the value is placed without decimal places, ex: 100000 (100 thousand)). However, when ordered in this way, it is not in the desired order, e.g.: 100000, 190000, 235000, 1000000, etc.

Follow the code below:

$orderby = array('post_type' => 
    'imovel', 'posts_per_page' => 12, 
    'paged' => get_query_var('page'), 
    'meta_key' => 
    'valor_do_imovel', 
    'orderby' => 'meta_value_num', 
    'order' => 'DESC'  
);  

$args = array_merge( $wp_query->query_vars, $orderby );

query_posts( $args );

During the searches, I found an article talking about using an SQL query for something like ORDER BY ABS, but my knowledge about SQL is very basic.

  • Do you want the order to be for the value of the property? From the smallest to the largest?

1 answer

1

  • I tested the code this way, and it still didn’t work. $orderby = array( 'post_type' => 'imovel', 'posts_per_page' => 12, 'paged' => get_query_var('page'), 'orderby' => array( 'meta_value_num' => 'DESC', 'valor_do_imovel' => 'DESC' ) And now an error appears: Warning: urldecode() expects Parameter 1 to be string, array Given in path/wp-includes/query.php. Something I’m still doing wrong?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.