Created
May 31, 2014 20:22
-
-
Save jchristopher/cdb6130c994b9feec8cd to your computer and use it in GitHub Desktop.
Replicate term whitelist exclusivity when searching in SearchWP (normally it's just when indexing)
This file contains 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 | |
function my_searchwp_search_regex_whitelist_exclusivity( $terms, $engine ) { | |
global $searchwp; | |
// we want to strip out any partial matches | |
$terms = ' ' . $terms . ' '; | |
$whitelisted_terms = $searchwp->extract_terms_using_pattern_whitelist( $terms ); | |
$terms = str_replace( ' ', ' ', $terms ); | |
// remove the matches | |
if( ! empty( $whitelisted_terms ) ) { | |
$terms = str_ireplace( $whitelisted_terms, ' ', $terms ); | |
} | |
// clean up the double space flag we used | |
$terms = str_replace( ' ', ' ', $terms ); | |
$terms = trim( $terms ); | |
return $terms; | |
} | |
add_filter( 'searchwp_terms', 'my_searchwp_search_regex_whitelist_exclusivity', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment