[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.
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?
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 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.
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.
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.
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?
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/