Support » Plugin: Relevanssi - A Better Search » Separating letters and numbers with spaces

  • Resolved agunda


    Hello you hard-working programmers. First of all I would like to praise you for your good work. I have tested a lot of plugins and can only rave about Relevanssi!

    But what I still need is a way to separate letters and numbers with spaces. For example, my customers are looking for “elac esg796”, but the product is called “elac esg 796”. Unfortunately, this is not only the case with the product, but with many others and I have seen so many customers who have left the website because they did not find what they were looking for.

    What possibility would I have to tweak the search?

    Many thanks for the support and remains so great 🙂

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Mikko Saari


    There are two approaches here. Either you can adjust the searches by inserting spaces, or you can make sure the products are indexed both ways, with spaces and without spaces.

    Adding spaces to the searches would look something like this:

    add_filter( 'relevanssi_modify_wp_query', 'rlv_add_spaces' );
    function rlv_add_spaces( $query ) {
        $query->query_vars['s'] = preg_replace( '/(\w)(\d)/', '\1 \2', $query->query_vars['s'] );
        return $query;

    Add this to your theme functions.php.

    Thread Starter agunda


    Hello, Mikko,

    Thank you so much for your efforts!
    In fact, it wasn’t the code, but the double indexing clue that led to the goal. So I simply enter the spelling in TAGS and already I have a man-made search for people.


    Thank you very much!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Separating letters and numbers with spaces’ is closed to new replies.