Loopers & custom sort of ACF fields

I have created a custom post type, via ACF, with fields “Reference”, “Location”, “Amount2” and “Status”.

I have also successfully created a page that displays them, using a looper with the following query.

post_type=practice-for-sale&posts_per_page=-1&orderby=meta_value&meta_key={{dc:url:param key=“orderby” fallback=“reference”}}&order={{dc:url:param key=“order” fallback=“desc"}}

Following Josh’s excellent video I have also added a series of buttons to the page to allow the user to select the required sorting. Each button passes the appropriate URL: i.e. ?orderby=amount2&order=asc

Unfortunately, the sorting - particularly on the Amount field is incorrect, even though the field type is set to numeric. Instead of being numeric, they come out in the order 117,900 , 120,000 ,152,000 , 19,000, 202,204, 22,600 and so on.

What am I doing wrong?

Hello @SimonCoatesPhotography,

Thanks for writing to us.

To help you with your concerns we need to check your setting, I would request please share the admin login details meanwhile I would suggest you troubleshoot a few of the common issues before we investigate your settings. Please share your details in a secure note. Please provide the following details

  • WordPress Login URL
  • Admin-level username and password
  • Exact page URL

You can find the Secure Note button at the bottom of your posts

Thanks

Hey @SimonCoatesPhotography,

Thanks for writing in!

You can only use orderby=meta_value when ordering a string. You should be using orderby=meta_value_num for numeric values.

Best Regards.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.