The pre_get_posts
filter is the right place to go. You can check if you are on a search query, and alter it the way you want. Here’s an example:
function search_filter($query) {
if ( !is_admin() && $query->is_main_query() ) {
// Check if we are on a search page
if ($query->is_search) {
// Get the search query
$search_term = get_search_query();
// You can modify the search query here, and pass it to the query again.
$search_term = str_replace( "-", "" , $search_term );
$query->set( 's', $search_term );
}
}
}
add_action('pre_get_posts','search_filter');