WordPress.org

Ready to get started?Download WordPress

Forums

Google Custom Search Plugin
patch to disable WP search queries (1 post)

  1. Anthony Somerset
    Member
    Posted 1 year ago #

    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();

    http://wordpress.org/extend/plugins/google-custom-search-for-wordpress/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

  • RSS feed for this topic
  • Started 1 year ago by Anthony Somerset
  • This topic is not resolved
  • WordPress version: 3.4.1