Skip Navigation

[Resolved] sorting by taxonomy Make the table sortable by columns

This support ticket is created 3 years, 8 months 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.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 2 replies, has 3 voices.

Last updated by Jamal 3 years, 8 months ago.

Assisted by: Jamal.

Author
Posts
#2098543
Screen Shot 2021-06-24 at 3.39.07 PM.png

I set up a table Make the table sortable by columns and I'm trying to sort by columns that are taxonomies. When I click on the "associated states" to sort, it doesn't organize it in any fashion that makes sense.

#2099069

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

Sorting by taxonomy isn't supported (it isn't an option with the underlying WP_Query class: https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters).

We have a usability problem here in that sorting controls shouldn't be offered for taxonomies because they don't produce meaningful results. I'm adding this thread to the internal ticket about that to boost the priority, but I don't have a solution for you, I'm afraid.

#2099283

Hello there! As Nigel explained, WP_Query, which Toolset uses under the hood does not support ordering using a taxonomy. If you need to order the table using a taxonomy, you will need to use a custom field for it instead of a taxonomy.

You can use a custom code, hooked to the save_post action, to synchronize the value of the taxonomy for each post into a custom field, and then you can use that custom field as a heading of the table. Does it make sense?
- https://developer.wordpress.org/reference/hooks/save_post/
- https://developer.wordpress.org/reference/functions/wp_get_post_terms/
- https://developer.wordpress.org/reference/functions/update_post_meta/

I hope this helps. Let me know if you have any questions.