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; ?>
  • 1
    Try it with a variable besides s. I think you are getting a conflict with the default search.
    – s_ha_dum
    Dec 29, 2012 at 16:50

1 Answer 1


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.

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.