Adding spaces in search phrase between alphabetics and numbers
Changing search input for better fuzzy matching
Issue example
Hello world 1235!hello12345Solution
// Adding whitespace between numeric and alphabetical words
add_filter(
'asp_query_args',
function ( $args ) {
$previous_char = '';
$new_string = '';
foreach ( mb_str_split($args['s']) as $char ) {
if (
( is_numeric($previous_char) && ctype_alpha($char) ) ||
( is_numeric($char) && ctype_alpha($previous_char) )
) {
$new_string .= ' ' . $char;
} else {
$new_string .= $char;
}
$previous_char = $char;
}
$args['s'] = $new_string;
return $args;
}, 10, 1
);Combined solution with extra character removal
PreviousReplace or remove characters from search phraseNextHow to change the results URL to something else?
Last updated