2

I currently have a search box in my sites header, (on every page), which sends the search query to a page called 'Search', which uses a template called searchpage. The page/template uses Google custom search to display the results.

Now this all works great, but I would like to use the built-in WordPress search to also return search results on the same page, above the Google results. Effectively using 1 search box to return 2 sets of results on the same page; 1 for WordPress and 1 for Google custom search.

Is this possible and how would I go about doing it?

1

3 Answers 3

0

The standard search results can also be formatted with a theme file, by default search.php. You don't need to create a "fake" page for that.

If you don't include any content from the page, and only use the theme file, you can just rename searchpage.php to search.php and it will work. If you do have some content that comes from a page written in the admin area, then you will have to query for this yourself (using get_posts() or another way), because the standard loop will only contain the search results, not that specific page.

So if you want to add the internal WordPress search results to the page, just add a classic loop at the top, and this should display the results.

1

You need a Google Custom Search Engine Replace your searchform with this code:

<form action="http://your.blog.url/index.php?s=" id="cse-search-box" class="searchform">  
  <input type="hidden" name="cx" value="your_CSE_ID" />  
  <input type="hidden" name="cof" value="FORID:10" />  
  <input type="hidden" name="ie" value="UTF-8" />  
  <label for="q">Search</label>  
  <input type="hidden" name="s" id="s" value="" />  
  <input type="text" name="q" id="q" class="keyword" />  
</form>  
<script>  
  jQuery('#q').bind('change', function() {  
    jQuery(this).val(function(i, val) {  
      jQuery('#s').val(val);  
      return val;  
    });  
  });  
</script>  
<script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&lang=de"></script>  

Use this code for the searchresults (after displaying the internal results):

<div id="cse-search-results"></div>
<script type="text/javascript">
  var googleSearchIframeName = "cse-search-results";
  var googleSearchFormName = "cse-search-box";
  var googleSearchFrameWidth = 600;
  var googleSearchDomain = "www.google.com";
  var googleSearchPath = "/cse";
  </script>
  <script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"></script>
-2

There's also the Google Custom Search plugin

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.