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

    (@msaari)

    add_filter('relevanssi_remove_punctuation', 'saveampersands_1', 9);
    function saveampersands_1($a) {
        $a = str_replace('&', 'AMPERSAND', $a);
        return $a;
    }
    
    add_filter('relevanssi_remove_punctuation', 'saveampersands_2', 11);
    function saveampersands_2($a) {
        $a = str_replace('AMPERSAND', '&' $a);
        return $a;
    }

    Add this to your functions.php and reindex the database.

    Thread Starter Stylediscount

    (@stylediscount)

    Thanks for your response Mikko! Could you maybe tell me where to place this exactly in the functions.php? I copy-pasted it after the last rule that was in there and it broke my site. I placed back the back up file but now I don’t want to try again and paste it somewhere else.

    Thanks in advance!

    Plugin Author Mikko Saari

    (@msaari)

    Anywhere, really, but if you have a ?> in the end of the functions.php, it has to go before that, as that signifies the end of PHP code.

    Also, I noticed there’s a typo in the code, might be that as well. It was missing a comma, and the correct code is:

    add_filter('relevanssi_remove_punctuation', 'saveampersands_1', 9);
    function saveampersands_1($a) {
        $a = str_replace('&', 'AMPERSAND', $a);
        return $a;
    }
    
    add_filter('relevanssi_remove_punctuation', 'saveampersands_2', 11);
    function saveampersands_2($a) {
        $a = str_replace('AMPERSAND', '&', $a);
        return $a;
    }
    Thread Starter Stylediscount

    (@stylediscount)

    It still doesn’t work. When I search for ‘H&M’ now, I still don’t get search results. If I look at the url of the search result I see: https://www.stylediscount.nl/?s=h%26m, so there might still be some error in that code?

    Plugin Author Mikko Saari

    (@msaari)

    Did you reindex the database after adding the code? It doesn’t work unless you do that. The URL is correct, & appears in urls as %26 so that’s just as expected.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Words with '&' sign not found’ is closed to new replies.