Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Created January 23, 2015 16:17
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 jchristopher/b0b41ef48c0b1e361967 to your computer and use it in GitHub Desktop.
Save jchristopher/b0b41ef48c0b1e361967 to your computer and use it in GitHub Desktop.
Filter each search term for a SearchWP search
<?php
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