Sarah Heer
Sarah Heer

Reputation: 5

Wordpress order by price listing

I have a problem with sorting by price on a wordpress site.

The sorting is in Descending order and it works correctly, if it were not for the ordering of the items by price it considers only the first two digits of the price, then an article with 2500 price is listed before one with price 210000.

How can I make the query consider the price as a whole and not just the first two digits?

this is the code:

$ args = array (
'post_type' => stm_listings_post_type (),
'post_status' => 'publish',
'posts_per_page' => intval ($ per_page),
'orderby' => 'meta_value',
'meta_key' => 'price',
'order' => 'DESC',
);

this the site: http://www.autoscarpa.com/

Upvotes: 0

Views: 166

Answers (1)

Zoha
Zoha

Reputation: 586

in args array change orderby value to meta_value_num

$ args = array (
    'post_type' => stm_listings_post_type (),
    'post_status' => 'publish',
    'posts_per_page' => intval ($ per_page),
    'orderby' => 'meta_value_num',
    'meta_key' => 'price',
    'order' => 'DESC',
);

Upvotes: 1

Related Questions