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 currently working on this website and a test shows that the search page isn't working properly. Every time someone searches for something, it comes up blank. The code for the search page is as shown below.

Search Form:

<form role="search" method="get" id="searchform" action="/search/" >
    <div><label class="screen-reader-text" for="s">Search for:</label>
    <input type="text" value="" name="s" id="s" />
    <input type="image" src="<?php bloginfo('stylesheet_directory'); ?>/images/searcher1.png"id="searchsubmit" value="Search" />

Search Page:

    if ( isset( $_REQUEST[ 'search' ] ) ) {
        // run search query
        query_posts( array(
            's' => $_REQUEST[ 'search' ],
            'post_type' => $_REQUEST[ 'post_type' ],

        ) );

        // loop
        if ( have_posts() ) : while ( have_posts() ) :
            // loop through results here
        endwhile; endif;

        // return to original query
share|improve this question
up vote 1 down vote accepted

Change action="/search/" to action="<?php bloginfo( 'url' ) ?>"

share|improve this answer
There's home_url() for that ;) – kaiser Nov 5 '12 at 18:12
Dead Medic, That didn't solve the problem, it didn't even go to the search page at all. – Dz.slick Nov 5 '12 at 18:13
@kaiser bloginfo( 'url' ) escapes & outputs home_url() - problem? – TheDeadMedic Nov 5 '12 at 18:30
@Dz.slick Well it should, since http://example.com/?s=search is treated as a search query :s – TheDeadMedic Nov 5 '12 at 18:31
@TheDeadMedic Problem? No. Not in every case. But this fn A) applies the filter and B) takes takes https://-situations into account. Not that this would work in every case – kaiser Nov 5 '12 at 19:22

You only need this part on your search page, delete all the rest

// loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
    // loop through results here
endwhile; endif;
share|improve this answer
+1. Get rid of the query_posts() call, and call the_post() as part of the Loop. To test: remove/rename search.php, and see if the search results render properly via the fallback, index.php. If they do, then your problem is query_posts() and the lack of the_post(). – Chip Bennett Nov 5 '12 at 17:41
Chip I did that and it still didn't work. – Dz.slick Nov 5 '12 at 17:53
If you try something, can you update your original question with 1) what you tried, 2) what happened/didn't happen? Since I suggested 2 things, I don't know which you tried, or what happened when you tried it. – Chip Bennett Nov 5 '12 at 19:56

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.