Skip Navigation

[Resolved] Alphabetic sort of checkboxes partially incorrect

This thread is resolved. Here is a description of the problem and solution.

Problem:
Is it possible to force alphabetic sort, regardless of whether an item is a parent or a child (via some function)? Like: B always comes after A and before C, no matter which one is a parent.

Solution:
Right now Views use the same logic as WP has for parent/child terms, I have submitted a request to our development team to improve it if possible. This might be possible using JS but I am not certain how.

This type of JS code or modifications falls into Custom coding & custom development and it is out of support policy (https://toolset.com/toolset-support-policy/). So we recommend to contact Toolset recommended service providers to further discuss the custom approach. We have some recommended list of service providers here if you would like to take a look: https://toolset.com/consultant/

This support ticket is created 7 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.

Sun Mon Tue Wed Thu Fri Sat
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 8 replies, has 2 voices.

Last updated by Thomas AMX 7 years ago.

Assisted by: Noman.

Author
Posts
#584661

Hi guys,

I noticed that Toolset sometimes has seemingly random problems with alphabetic sorting.

On my current site, I have Views/Archives with parametric search. There are checkboxes with taxonomy terms, and in most cases everything is fine. The terms are sorted alphabetically. But in certain cases, an individual term is not displayed where it should be according to the alphabetic sort. It doesn't matter whether it is DESC or ASC, or by slug vs. by name. When an item is affected, it will always be in an incorrect position in these two sorts and most of its neighbors will be where they should be.

On an older site with Avada, I had a similar issue with Tags in Post templates. Avada sorted them correctly, but in a Toolset post template, some of them (a very small minority) would be in incorrect positions.

I ignored this issue with the tags, but I would really like the checkboxes to be sorted alphabetically (by slug or name, it doesn't matter much). In one case, B comes after C and P. I double checked the taxonomy term name and slug - and it starts really with a B. I cannot use sort by ID, because the list of terms will grow...

It's weird and I don't understand why it happens. It seems to affect random terms, but always the same ones. When an item is affected, it will always be affected.

Have you experienced something like this and do you know how to fix it?

Cheers
Tom

#584720

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Thomas,

Thank you for contacting Toolset support. Sometimes the other order/sort plugin conflicts with View order. Please try to check it by deactivating all third-party plugins (except Toolset) and switching back to the Default Theme (e.g. Twenty Sixteen theme) to see for any possible conflicts with any of the plugins or themes?

If still issue persists, please provide temporary access (WP-Admin and FTP Login info) to your site (preferably staging site), so that I can look into your setup and check the issue.

Your next answer will be private which means only you and I have access to it.

=== Please backup your database and website ===

✙ I would additionally need your permission to de-activate and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important.

✙ Please provide View/Archives Edit link and front-end link, checkbox field name, any other link related to this.

Thank you

#587888

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for providing login details. I am working on it right now and will update you with details shortly.

Thank you

#588080

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Test view.png
View.png

Hello Thomas,

I have checked your site and found that checkboxes are sorting fine. It shows all the Parent terms first then shows child terms.

I have created a new View to test this -- see attached screenshots.

Thank you

#588145

Hello Noman,

Thank you for your response. Is it possible to force a true alphabetic sort then, regardless of whether an item is a parent or a child (via some function)? Like: B always comes after A and before C, no matter which one is a parent.

I see there is certain logic behind the default behavior, and it's good, but on the front-end it may sometimes appear as 'messy' to some visitors.

Cheers
Tom

#588213

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Thomas,

I have again checked the issue in your site and find out that the issue is basically happening for child terms. The default ordering of [wpv-control-post-taxonomy] shortcode is by 'name' but it does not handle child terms very well.

In the shortcode doc: https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-control-post-taxonomy
We have orderby & order attributes, I tried to manually add these to the shortcode for the filters but that also keeps it same, in the doc you will see:

orderby = 'name' (default)
order = 'ASC (default)'

Changing these attribute values work good but the child terms thing stays the same. So I have now submitted this as an improvement request to our team for the filters.

Alternatively, I recommend to manually arrange child terms or terms using an ordering plugin to manually arrange the orders of the terms:
- https://wordpress.org/plugins/taxonomy-terms-order/
- https://wordpress.org/plugins/custom-taxonomy-order-ne/

Thank you for your understanding.

#588265

Thank you Noman.

From what I can see, these plugins allow only to arrange manually sibling terms within their parents, so trying to create an alphabetic sort could break the hierarchy. Maybe this behaviour is a WordPress thing... And maintaining large taxonomies in this way would be extremely time-consuming anyway.

Perhaps a better approach would be to sort them with javascript in the DOM? I found this:
hidden link

But I cannot make it work. I added my custom div id "places" and added this to JS section:

var sortByText = function (a, b) {
     return $.trim($(a).text()) > $.trim($(b).text());
 }
 $(document).ready(function () {

     var sorted = $('#places label').sort(sortByText);
     $('#places').append(sorted);

 });

But it seems to be ignored on my page, although it works in the jsfiddle example.
Is there a way to make it work or perhaps there is a better jQuery trick?

#588637

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello,

Right now Views use the same logic as WP has for parent/child terms, I have submitted a request to our development team to improve it if possible. This might be possible using JS but I am not certain how.

This type of JS code or modifications falls into Custom coding & custom development and it is out of support policy (https://toolset.com/toolset-support-policy/). So we recommend to contact Toolset recommended service providers to further discuss the custom approach. We have some recommended list of service providers here if you would like to take a look: https://toolset.com/consultant/

Thanks

#588684

All right, thanks Noman.

Cheers

Tom