Home › Forums › Backend Issues (wp-admin) › Sorting the results of taxonomy field
We are trying to sort the results listed in a Taxonomy field of ACF. The words that we want to display as suggestions are added in a terms/taxonomy called Ingredients. Currently the terms are sorted alphabetically. However, we would like to implement a custom sorting rule where the results that start with the typed in part are listed on top of the list, followed by other suggestions. For example, if looking for we are searching for “sugar” the results would be something like:
– sugar
– sugar powder
– brown sugar
– palm sugar
– …etc
I know how to implement the sorting algorithm in PHP. However, the issue is where to place the code so that this change will be reflected in the WordPress admin panel when editing posts. I’ve added a picture to this post to visualize the part that we want to change.
Any ideas? We’ve already tried Custom Taxonomy Order addon, but that one does not allow for custom sorting in code: https://wordpress.org/plugins/custom-taxonomy-order-ne/ and
bump, here is the image link that is not working in the original post:
The only way that you can alter the order of the terms in an ACF taxonomy field would be to use acf/fields/taxonomy/query and the sorting would need to be something you could apply to a term query using the order/orderby arguments.
I am having the same problem where I need to order the terms by php’s natural sort function.
But through the acf/fields/taxonomy/query filter the only thing you can change is the orderby argument, but you can’t add a custom sort function or better yet sort the result before returning it.
You must be logged in to reply to this topic.
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.