[Plugin: Google Custom Search Plugin] patch to disable WP search queries
-
we found that with this plugin enabled in some cases the search query was still also being performed on the DB even though it was returning google results (particularly when not using the iframe option)
here is a patch that will change the global search query to disable it when you activate the plugin so that it only uses Google CSE for searching and search results:
diff --git a/wp-content/plugins/google-custom-search-for-wordpress/GoogleCSE.php b/wp-content/plugins/google-custom-search-for-wordpress/GoogleCSE.php index 57b7d66..328f950 100755 --- a/wp-content/plugins/google-custom-search-for-wordpress/GoogleCSE.php +++ b/wp-content/plugins/google-custom-search-for-wordpress/GoogleCSE.php @@ -26,6 +26,7 @@ class GoogleCSE add_filter('get_search_form', array('GoogleCSE', 'get_form')); add_action('template_redirect', array('GoogleCSE', 'template_redirect'), 1); add_action('admin_menu', array('GoogleCSE', 'admin_config_page')); + add_filter('posts_request', array('GoogleCSE', 'changeRequest')); // setup user options self::$search_url = get_option('home') . '/search/'; @@ -170,7 +171,15 @@ class GoogleCSE return $form; } - + + public static function changeRequest( $request ) + { + global $wpdb; + if ( is_search() ) { + $request = "SELECT ID FROM {$wpdb->posts} WHERE 1=0 limit 1"; + } + return $request; + } } GoogleCSE::run();
https://www.ads-software.com/extend/plugins/google-custom-search-for-wordpress/
- The topic ‘[Plugin: Google Custom Search Plugin] patch to disable WP search queries’ is closed to new replies.