Non exact matching

This topic contains 1 reply, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 7 years, 8 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #10943


    I have some products on my site which have ‘VX-3’ as part of their name and in their content. If I search for VX-3 I get a list of all the products to choose from. However I would like the user to be able to type in VX3 (without the dash) and get the same results. Is this possible? I have spent hours on altering th behaviour settings without any luck.

    Also, currently when you do type in VX3 I get a list of ‘Did you mean:’ suggestions, which don’t mean anything. how do I stop this?


    Ernest Marcinko
    Ernest Marcinko

    Hi Chris,

    Because the data is stored as “VX-3” there is no possible way of matching it with “VX3” without making a modification to the search phrase of some sort. MySQL does not support so called close matching inbetween a string.

    The only possible solution is to perhaps use a custom code to watch the search phrase and change it if neccessary according to a pattern. I’m guessing in your case changing “XYZ123” to “XYZ-123” would be the solution. In this case I would recommend putting the following code to the functions.php file in your theme directory:

    I have not fully tested this solution, so please be careful. It should put a dash character before any number that is adjacent to a non-numeric character.

    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.