Skip Navigation

[Resolved] Sort taxonomy by custom field internal to a form

This support ticket is created 5 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 1.16 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 1 reply, has 2 voices.

Last updated by Christian Cox 5 years ago.

Assisted by: Christian Cox.

Author
Posts
#1360641

I have a form called "Activity". The form has a taxonomy "Days of the Week", with elements Monday, Tuesday, etc. The "add Activity" form displays the Days of the Week in alphabetical order (Friday, Monday, Saturday, etc.). I can add "1 Sunday", "2 Monday", but that clutters up the selection, especially since it's also a query field for a different
view.

I added a "sort order" custom field to the taxonomy, but it's not selectable when adding the taxonomy field to the form, so it's not usable for this purpose. I don't see any way to include a query over taxonomy and add that to the form either.

What is the link to your site? Behind a firewall.

#1360893

Hi, there's no built-in way to assign an arbitrary order to these field options, unfortunately. One way you could achieve this sorting is to create a generic field and populate the options for each term manually. Since there are only 7 options to consider, this shouldn't be too difficult to maintain. Use the cred_save_data hook to capture the User's selection and add the appropriate term or terms to the post after the form is submitted.

https://toolset.com/documentation/user-guides/inserting-generic-fields-into-forms/
https://toolset.com/documentation/programmer-reference/cred-api/
https://codex.wordpress.org/Function_Reference/wp_set_object_terms

Let me know if you have questions about using Toolset's APIs and I'll be glad to offer guidance.