I have a custom post called Cars and each post has a ACF called Price.
Is it possible to order the post by the price so e.g. most expensive first, least expensive last?
This is what I have so far, but it’s just putting them in order of published.
$args = array(
'post_type' => 'cars',
'posts_per_page' => 999,
'meta_key' => 'price',
'orderby' => 'meta_value',
'order' => 'ASC'
);
I’ve googled it, but struggling to find anything useful (maybe I putting in wrong search terms…)
Try this and let me know what you get:
$args = array(
'post_type' => 'cars',
'posts_per_page' => 999,
'meta_key' => 'price',
'meta_type' => 'NUMERIC',
'orderby' => 'meta_value_num',
'order' => 'ASC'
);
Hi @bosoxbill
Thanks for getting back to me, sadly it didn’t work. It put the car at £11,000 at the bottom with a £12,000 and £7,000 above it.
UPDATE
Went back and removed the £ sign from the fields and tested again, worked! Thanks! 🙂