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

Search Page:

<?php
    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
        wp_reset_query();
    }
share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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

share|improve this answer
2  
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
1  
@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
show 3 more comments

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  
+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
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.