Skip Navigation

[Resolved] I need to filter Views by alphabetic groups – A-L, M-R, and S-Z .

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

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)

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by Anthony 3 years, 6 months ago.

Assisted by: Jamal.

Author
Posts
#2055527

I have a CPT with a over two hundred artist records, including a custom field for Last Name. My client wants these artists grouped onto three pages with last names grouped alphabetically by A-L, M-R, and S-Z , and I need help in setting up filtering for three Views accordingly.

#2056033

Hello and thank you for contacting the Toolset support.

This can't be done with Toolset or WP_Query without some custom code. Because the WP_Query does not offer a "starts with" operator. It offers a "LIKE" operator, but it will need custom code to change the SQL query and remove the first % from it. Check these online threads:
- https://stackoverflow.com/a/10104988
- https://wordpress.stackexchange.com/a/346733

However, I would like to suggest a different approach. Why not use a custom taxonomy for it. The terms of the taxonomy will be the letters, and you can add a custom hook to sync the taxonomy based on the custom field value. Check a similar case, where my colleague Christian has suggested using another custom field. However, queries based on taxonomies are faster than queries built with a custom field. In addition, a custom taxonomy will provide more features, such as the count of posts, cloud tags, etc.
- https://toolset.com/forums/topic/how-to-filter-by-the-first-character-of-a-custom-field/

I hope this answers your question. Let me know if you have any questions.

#2056045

I think the problem with the taxonomy approach is problematic if it only addresses the first character of the field involved.

What I would really like to be able to do is apply two filter conditions to the same field, as is possible for example with Date fields, but apparently not with other field types. In the absence of such functionality, I'm thinking I should create a duplicate of the field I want to filter and then apply the second condition to that...

#2056091

A custom taxonomy will be faster than a second custom field. Honestly, I don't see a case where a custom taxonomy is not a good solution.

A second field is also a viable solution. Please check Christian suggestion from this similar thread https://toolset.com/forums/topic/how-to-filter-by-the-first-character-of-a-custom-field/

Let me know if you have any further questions.

#2056119

Why is is possible to have two filter conditions for Date fields (i.e. greater than date1 AND less than date2) but not for a string field?