Skip Navigation

[Resolved] Sorting values on a CRED from

This support ticket is created 4 years, 1 month 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

This topic contains 6 replies, has 2 voices.

Last updated by simonM-5 4 years, 1 month ago.

Assisted by: Nigel.

Author
Posts
#1551435

Tell us what you are trying to do?
In one of our CRED post forms, we are displaying the values of a taxonomy, but there doesn't appear to be a neat way of displaying the items from the taxonomy in a sensible manner, other than the default alphabetical sort.

Eg we have a taxonomy AVAILABLE DAYS which I would like to display in the logical order for days of the week, ie Monday, Tuesday, ... , Sunday. I could achieve this easily if I could sort by slug.

Is there any documentation that you are following?
https://toolset.com/documentation/user-guides/front-end-forms/cred-shortcodes/#cred_form

I've also seen a few posts on this in your support forum, but they are several years old and I wondered had this feature been improved and perhaps remained undocumented?

Do you know of a non-complicated way to display the taxonomy terms sorted by slug asc? Or is there an easy workaround?

Thanks and regards
Simon

#1551437

Please rename the post to Sorting values on a CRED form, if easily possible.. 🙂

#1552021

Nigel
Supporter

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

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

Hi Simon

There are no options for modifying the ordering settings for the taxonomy terms.

Overriding the existing order would ordinarily require custom code.

I was just looking into an example using pre_get_terms and I thought it would be nicer rather than you having to tweak the term stubs to get the right order to use a plugin that offers you a drag and drop interface to set your order, and to then use a code snippet to make sure the form uses that custom order when outputting the terms.

But when I set up a quick test with my preferred plugin for this, I found the custom code wasn't required, the form displayed the terms in the manual order anyway.

So, try installing WP Term Order (https://wordpress.org/plugins/wp-term-order/), then drag and drop the terms into a sensible order.

You should see that reflected in the front end form.

The plugin doesn't have a lot of users, but it is by a core contributor and is a simple clean plugin that does one thing well.

#1552089

HI Nigel

Thanks for that. I have spotted a few other plugins with similar functionality. I will need to try them all out and see how they behave with translations. Eg Monday to Sunday might work in English but it would not work in Spanish... Also I noticed that the default alphabetical order has gone now too in English for all other taxonomies we had that were just displayed in alphabetical order (which made sense for the front end user), so this is another one I'll need to test in another language too...

Wouldn't it be an idea to develop a orderby argument for the cred_field taking parameter (name, id, slug, date) and a sort argument taking (asc, desc)? This seems so fundamental to me, I'm surprised it hasn't been requested by everyone else yet and developed by Toolset. Feature request?

I guess this might need to be a joint effort between Toolset and WPML due to the translations?

Thanks and best regards
Simon

#1552091

Hi Nigel

I forgot to mention: when I activated the plugin, it gave me a message, which appeared once and then was never to be seen again.

[Unknown column 'tt.order' in 'order clause']
SELECT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id LEFT JOIN wp_icl_translations icl_t ON icl_t.element_id = tt.term_taxonomy_id AND icl_t.element_type IN ('tax_slide-page') WHERE tt.taxonomy IN ('slide-page') AND ( ( icl_t.element_type IN ('tax_slide-page') AND ( icl_t.language_code = 'en' OR 0 ) ) OR icl_t.element_type NOT IN ('tax_slide-page') OR icl_t.element_type IS NULL ) ORDER BY tt.order ASC

I cannot say whether it can be ignored now or whether there will be an underlying problem which will raise its ugly head later. The plugin is quite old and untested on our version. The newer plugins may prove more valuable.

Kind regards
Simon

#1552303

Nigel
Supporter

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

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

Hi Simon

I'm not sure how this would interact with WPML, I guess that would require some testing.

I suggested that plugin even though it is aging because it's by a core contributor and does one simple thing, but I'm not sure what to expect when you throw WPML into the mix.

Instead of using a plugin, you could use custom code instead, using the pre_get_terms hook to modify the query arguments per your needs (https://developer.wordpress.org/reference/hooks/pre_get_terms/).

And please, by all means submit a request for more control over front-end taxonomy filters (Views filter controls and Toolset Forms), including modifying which terms are included, as well as ordering options for the terms. Filing such a request helps our product manager gauge demand when it comes to development priorities.

https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

#1555127

HI Nigel

I'm not a PHP developer (yet! 😅) so I wouldn't know where to start with pre_get_terms.

I tried out several plugins with varying results. The one you recommend seems to do the job fine, despite throwing that message at the beginning on first activation. It's simple and intuitive to use and also allows different orders in the different languages with WPML, so just what I was looking for. I just hope it doesn't break at some point in the future! 😁

I'd be more than happy to write a feature request for CRED forms.

Best regards
Simon

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.