Skip to content

Instantly share code, notes, and snippets.

@searchwpgists
Created March 9, 2022 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save searchwpgists/f4dec5c63e1ae9e0c102e29a01d25fa5 to your computer and use it in GitHub Desktop.
Save searchwpgists/f4dec5c63e1ae9e0c102e29a01d25fa5 to your computer and use it in GitHub Desktop.
Customize SearchWP stopwords per Engine
<?php
/**
* Customize SearchWP stopwords per Engine.
*/
// Optional: remove all Stopwords so you can add only unique Stopwords per Engine.
add_filter( 'searchwp\stopwords', '__return_empty_array' );
// Add unique stopword(s) for a single SearchWP Engine.
add_filter( 'searchwp\query\search_string', function( $search_string, $query ) {
// Remove "apple" and "orange" for my_engine searches.
if ( 'my_engine' === $query->get_engine() ) {
$search_string = str_replace( [ 'apple', 'orange' ], '', $search_string );
}
return $search_string;
}, 20, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment