Skip to content

Instantly share code, notes, and snippets.

@lumpysimon
Last active July 6, 2021 20:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lumpysimon/dd2c8043bc271acb497dc2dd8368ebde to your computer and use it in GitHub Desktop.
Save lumpysimon/dd2c8043bc271acb497dc2dd8368ebde to your computer and use it in GitHub Desktop.
Exclude spammy searches from SearchWP
add_filter( 'searchwp\statistics\log', 'my_log_filter', 10, 2 );
function my_log_filter( $enabled, $query ) {
$search_string = $query->get_keywords();
$long = ( strlen( $search_string ) > 30 );
$www = ( 'www' === substr( $search_string, 0, 3 ) );
$slashes = ( false !== strpos( $search_string, '/' ) );
if ( $long or $www or $slashes ) {
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment