WordPress Search Queries

I have added within my WordPress 3.1 site, the following code at the bottom of my sidebar.php file:

    <div id="search_box">
      <form id="searchform" action="http://www.service.com/" method="get" role="search">
          <input id="s" type="text" name="s" class="search" value="Search site" size="19" maxlength="80" id="white_box" onfocus="if (this.value=='Search site') this.value = ''"/>
          <input id="searchsubmit" type="image" class="submit" value="submit" src="<?php bloginfo( 'template_url' ); ?>/images/search_btn.jpg" />
      </form>
    </div>

As I have coded this search process myself, when I place a some text within my search text box and press the “Search” button, it looks as if, is is calling the page search.php within my theme and displaying the results.

Read More

Questions:

1) where/how does it know when I press the “Search” button to go off and call search.php?

2) if possible only, how can I change it to call a different php file instead of the search.php

Thanks.

Related posts

Leave a Reply

3 comments

  1. Use template filter

    add_filter( 'template_include', 'template_include', 10 );
    

    and change the template as

    function template_include($template)
    {
    
        if(your condition here){
            $template = get_template_directory().'/your-template.php';
        }
    
        return $template;
    }
    
    1. WordPress assumes the request is a search if it sees an ‘s’ GET variable.

    2. You can hook into the template_redirect action (in your theme’s functions.php file) and load a different template like so:

      add_action('template_redirect', 'my_template_select');
      function my_template_select() {
        if (is_search()) {
          load_template(TEMPLATEPATH . '/foobar.php');
          exit;
        } 
      }