Skip Navigation

[Resolved] Ignore Special Characters in WP Search

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

Problem:
I'm building a "parts" website. The client wants users to be able to search for parts, with or without using special characters, such as "-" or "/".

For instance, a customer should be able to search for "4-24864-0180" or "4248640180", and get the same results.
Solution:
If you are going to achieve what you want with wordpress built-in search form + Relevanssi plugin, it is out the range of Toolset support range, I suggest you contact with Relevanssi supporters.

If you are using Views to setup the custom search form, then it is possible with some custom codes, you can try with Views filter hook wpv_filter_query, for example:
when your user submit the search string "4-24864-0180", you can use filter hook wpv_filter_query to trigger a custom PHP function, in this function get the value of search string, turn it to be the value without dash "-": 4248640180
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

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

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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: Asia/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by Ed 7 years, 2 months ago.

Assisted by: Luo Yang.

Author
Posts
#569082

Ed

I'm building a "parts" website. The client wants users to be able to search for parts, with or without using special characters, such as "-" or "/".

For instance, a customer should be able to search for "4-24864-0180" or "4248640180", and get the same results.

Is this possible? I have Relevanssi installed, but I don't see an option to ignore special characters. "Fuzzy search" doesn't give the needed results.

I've also seen the custom search documentation, which I'll be reading up on, but I don't think it offers an answer to my question.

Thank you.

#569127

Dear ED,

If you are going to achieve what you want with wordpress built-in search form + Relevanssi plugin, it is out the range of Toolset support range, I suggest you contact with Relevanssi supporters.

If you are using Views to setup the custom search form, then it is possible with some custom codes, you can try with Views filter hook wpv_filter_query, for example:
when your user submit the search string "4-24864-0180", you can use filter hook wpv_filter_query to trigger a custom PHP function, in this function get the value of search string, turn it to be the value without dash "-": 4248640180

More help:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
When displaying a View listing posts, this filter is applied to the arguments being generated by the View settings before they are passed to the WP_Query class.

#569143

Ed

Thanks, Luo. I'll contact Relevanssi, to see what they have to say.