Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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;">      
           </form>

Search page code:

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

$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; ?>
?>  
</div><!--search_page-->
<?php
get_footer(); 
share|improve this question
1  
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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.