Skip to content

Instantly share code, notes, and snippets.

@seancojr
Forked from Viper007Bond/gist:1297669
Created April 21, 2012 22:08
Show Gist options
  • Save seancojr/2439915 to your computer and use it in GitHub Desktop.
Save seancojr/2439915 to your computer and use it in GitHub Desktop.
Determining if modifying the main query or not in WordPress
<?php
# See bigdawggi's comment below for a good combined example
// Pre-3.3
function cf_google_search_kill_wp_search( $where, $query ) {
global $wp_the_query;
if( ! is_admin() && $query->is_search() && $query === $wp_the_query ) {
$where = ' AND 1=0';
}
return $where;
}
add_filter( 'posts_where', 'cf_google_search_kill_wp_search', 10, 2 );
// Post-3.3
function cf_google_search_kill_wp_search( $where, $query ) {
if ( ! is_admin() && $query->is_search() && $query->is_main_query() ) {
$where = ' AND 1=0';
}
return $where;
}
add_filter( 'posts_where', 'cf_google_search_kill_wp_search', 10, 2 );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment