@replace @arr $restricted
// Disallow users from searching specific terms on your site
add_filter( 'pre_get_posts', function( $query ) {
$restricted = array(
'term-1',
'term-2'
);
if ( $query->is_search && $query->is_main_query() ) {
$stripped = trim( str_replace( $restricted, '', $query->get('s') ) );
if ( $stripped == '' )
$query->set( 'p', -1 );
else
$query->set( 's', $stripped );
}
} );