Wordpress - Order by meta value num

0

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

I am using the meta_value_num sort order from a meta_key that goes the value of some properties (the value is placed without decimals, eg: 100000 (100 thousand)). However, when ordered in this way, it is not in the desired order, eg 100000, 190000, 235000, 1000000, etc.

The following is 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 searches, I found an article talking about using a SQL query for this something like ORDER BY ABS , but my SQL knowledge is pretty basic.

    
asked by anonymous 26.01.2015 / 21:09

1 answer

1

orderby must be meta_value_num , or meta_value , not the key name.

Example:

$orderby= array(
    'orderby'  => array( 'meta_value_num' => 'ASC', 'valor_do_imovel' => 'ASC' )

SEE : link

    
26.01.2015 / 21:41