Replace or remove characters from search phrase
By default the plugin allows searching any character without restriction. If you however need to replace (or remove) certain special characters, use the code below.
1
add_filter('asp_search_phrase_before_cleaning', 'asp_replace_characters', 10, 1);
2
add_filter('asp_query_args', 'asp_replace_characters', 10, 1);
3
4
function asp_replace_characters( $s ) {
5
$characters = "',._-?!"; // Type characters one after another
6
$replace_with = ' '; // Replace them with this (space by default)
7
8
if ( is_array($s) ) {
9
if ( isset($s['s']) && !$s['_ajax_search'] )
10
$s['s'] = str_replace(str_split($characters), $replace_with, $s['s']);
11
} else {
12
$s = str_replace(str_split($characters), $replace_with, $s);
13
}
14
15
return $s;
16
}
Copied!
Type the characters into the $characters variable, one after another. By default it replaces it with a space character. In case you want to remove those characters, change the
1
$replace_with = ' ';
Copied!
with:
1
$replace_with = '';
Copied!
Last modified 1yr ago
Copy link