Skip to content

Instantly share code, notes, and snippets.

@mjangda
Created February 10, 2012 19:54
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 mjangda/1792216 to your computer and use it in GitHub Desktop.
Save mjangda/1792216 to your computer and use it in GitHub Desktop.
Kills WordPress search query
<?php
add_filter( 'posts_where', 'x_kill_search_query', 10, 2 );
function x_kill_search_query( $where, $query ) {
if ( ! is_admin() && $query->is_main_query() ) {
// this is a self-removing callback
remove_filter( current_filter(), __FUNCTION__, 10 );
if ( $query->is_search() ) // only kill the main query
$where = ' AND 1=0 /* Query killed */';
}
return $where;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment