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 have a custom searchform.php and search.php in my theme. However, when searching for something all I see is the front page (with mysite.com/?s=something in the adressbar). I use a filter to make Wordpress use my custom search form (don't know why it won't use it otherwise). The search does work when I use a different theme.

Filter code snippet in functions.php:

function search_form_no_filters() {
  // look for local searchform template
  $search_form_template = locate_template( 'searchform.php' );
  if ( '' !== $search_form_template ) {
    // searchform.php exists, remove all filters
    remove_all_filters('get_search_form');
  }
}
add_action('pre_get_search_form', 'search_form_no_filters');

My searchform.php

<form id="searchform" action="<?php echo home_url( '/' ); ?>" method="get" role="search">
    <div class="input-group">
        <input id="s" type="text" name="s" class="form-control">
        <span class="input-group-btn">
            <button class="btn" type="button" id="submit">Go</button>
        </span>
    </div>
    <script>
        jQuery(document).ready(function($){
            $('#searchform #submit').on('click', function(){
                $('#searchform').submit();
            }); 
        });
    </script>
</form>

For debugging purposes I currently use search.php from the Twentyfourteen theme.

I've researched this problem and it seems that the most common mistake is that the search query input field has a name other than "s". I got that right though.

share|improve this question
    
What have you done to debug? If you remove your searchform.php, and search using the default search form, does your Theme's search.php load properly? If you remove your custom filter, does your Theme's search.php load properly? –  Chip Bennett Apr 14 at 16:36
    
It does not work even when I use the default search form and search with no filter. –  eevaa Apr 14 at 17:03
    
And if you remove search.php, does the search results index load properly? –  Chip Bennett Apr 14 at 17:30
    
No. But I just noticed that it does show "Results for 'something'" as the page title (at the top of the browser window) with and without search.php –  eevaa Apr 14 at 18:31
    
So how do you know that the search template is not being shown? Are you testing with a valid search term? –  Chip Bennett Apr 14 at 18:32

1 Answer 1

Why you are using this filter code, WordPress will still use searchform.php code, without it?

Further, it could be some issue with the loop code within search.php. Twentyfourteen theme looks for content-[post-format].php file. Do you have one in you theme root?

get_template_part( 'content', get_post_format() );

try using this simplified loop in search.php ...

        <?php if(have_posts()) : while(have_posts()) : the_post(); ?>

            <?php the_content(); ?>

        <?php endwhile; endif; ?>
share|improve this answer
    
I also tried search.php-files from other themes and I tried a highly simplified search.php that would only output the posts' titles. Nothing worked. –  eevaa Apr 14 at 18:34
    
still there could be some problem in other search.php code, but not sure about it. I've updated the answer. It might help somehow. –  Faisal79c2 Apr 14 at 18:46
    
Still doesn't work. –  eevaa Apr 14 at 18:50

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.