Skip Navigation

[Resolved] Modify order by title

This support ticket is created 5 years, 6 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.

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

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 2 replies, has 2 voices.

Last updated by katjaL 5 years, 6 months ago.

Assisted by: Beda.

Author
Posts
#1245294

I have this directory site, where subscribers can add their post. For visitors there are two ways to order the results, by title or by last updated. Ordering by title (a,b,c...) brings special characters like . to top. This rises unwanted effect, some subscribers add special character to start of their title to get first in results.

Is there a way to filter out this kind of result or move them to end of the list, after z?

#1245315

Order by works either on strings, or numbers, but not both at once.
This is also visible in the native ordering of Posts in the Admin Posts list - WordPress orders natively by string and hence will break numerical ordering to a string ordering.
It does the same with special characters.

This means, a string will be ordered alphabetically, a number or special character will be interpreted as a string and hence be ordered by the number of characters in that string since one cannot order numerical values by string or opposite.

If set to ASC, such query first returns Special Signs from 1-N items (unless there are letters in the string of special characters, then it's first N of special characters, second the letter from A-Z), then Numbers from 0-N, then letters from A-Z or the other way around, first letters from Z-A, then Numbers from N-0, then Special Signs from N-1 item.

So your only chance to have those at the bottom is to change from ASC to DESC in the allover ordering.

On another hand, one would need to alter the query and loop in custom regex as shown in this Post to only order by Letter, let's say:
https://stackoverflow.com/questions/11641370/how-to-sort-mysql-results-with-letters-first-symbols-last

You could maybe simply exclude those posts from the results altogether.
There are several ways to do this, but the best would be to validate the input (In Forms, or wherever people create posts) ensure only expected data is submitted. This can be done with custom validation code or using specific fields, and more.
Another option is to validate the output before passing it to the queries with a filter of Views https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

Please let me know if you need help with validation of input, I can give a few ideas on how to achieve this.
Mainly you'd hook on a cred_save_data() action and simply delete unwanted characters from the post, or, you could use Forms Conditions to not even let the user submit the Form if they use special characters.
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://toolset.com/documentation/user-guides/conditional-display-for-form-inputs/

#1245952

Thank you Beda for clearing the possibilities, very helpful!