Created
October 7, 2020 13:22
-
-
Save jchristopher/ec0512bc15d25d322f1f37a903bd2665 to your computer and use it in GitHub Desktop.
Customize SearchWP stopwords per Engine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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