Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Filter each search term for a SearchWP search
function my_searchwp_term_in( $term, $engine, $original_term ) {
// $term is an array because other filters may have broadened the search already (e.g. LIKE Terms extension)
// $original_term is the original, unaltered term
// if someone searched for "NYC" we need to convert it to "New York City"
// because we never write "NYC" and always write "New York City"
if ( 'nyc' == strtolower( $original_term ) ) {
$term = explode( ' ', 'New York City' ); // keep it an array
return $term;
add_filter( 'searchwp_term_in', 'my_searchwp_term_in' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment