Home › Forums › General Issues › Order Posts by Custom Fields When Meta Key Already In Use › Reply To: Order Posts by Custom Fields When Meta Key Already In Use
Thanks again for your help…
I can’t say I had a good understanding of the information on that page, but I’ve managed to solve my problem.
$args = array( 'numberposts' => -1, 'post_type' => 'cars', 'meta_query' => array( 'state_clause' => array( 'key' => 'sold', 'value' => '0' ) ), 'meta_key' => 'price', 'orderby' => 'meta_value', 'order' => 'ASC', 'posts_per_page' => 12, 'paged' => $paged );
As you can see, I’ve used the meta_query to filter out the sold vehicles, allowing me to use the meta_key to order the results.
I’ve got a bit of a glitch going on though…
Any prices starting with 1 are at the beginning and any starting with 9 are at the end etc.
This has resulted in £30,000 cars being next to £300,000 cars.
I’ve checked the type for the Price field and it’s “number”.
Am I missing something simple or should I have done the ordering via meta_query as well?
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
🚨 The 2023 ACF Annual Survey closes tomorrow! This is your last chance to complete the survey and help guide the evolution of ACF. https://t.co/0cgr9ZFOJ5— Advanced Custom Fields (@wp_acf) May 18, 2023
© 2023 Advanced Custom Fields.