WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to create a general search page. I've created a search page template and a new search page, and set the form's action to the URL of this page.

When I access the search page directly it fetches the right template, but when I try to send a form to this URL, be it via $_GET or $_POST, I am directed to the default index.php template.

Form code:

<form action="<?php echo get_permalink(359); ?>" method="GET">
               <input name="s" type="text" id="search_box">
               <input type="submit" value="submit" style="visibility:hidden;">      

Search page code:

<?php // Template Name: חיפוש 
get_header(); ?>
<div id="search_page">

$search = new WP_Query(array('s'=>$_GET['s']));

if ($search->have_posts() ) : while ( $search->have_posts() ) : $search->the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_excerpt();
endwhile; ?>
<!-- post navigation -->
<?php else: ?>
<!-- no posts found -->
<?php endif; ?>
share|improve this question
Try it with a variable besides s. I think you are getting a conflict with the default search. – s_ha_dum Dec 29 '12 at 16:50
up vote 3 down vote accepted

When a search is performed, the default query is no longer a page query, it becomes a search query. Refer to the template hierarchy to see how WP selects the template in this case. Rename the get var to something unique, or filter search_template to override WP's selection.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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