search.php template not loading results

admin2025-06-06  8

This is really bizarre - this has never happened before :/


I have a search.php template which consists of this...

    <?php
    /**
    * @package WordPress
    * @subpackage Example 2012
    * @since Example 1.0
    */

    get_header(); ?>


    <?php if (have_posts()) : ?>

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

    <?php the_title(); ?>

    <?php endwhile; ?>

    <?php endif; wp_reset_query(); ?>


    <?php get_footer(); ?>


this is what is in my functions.php

// SEARCH FORM HEADER
function search_form_header( $form ) {
    $form = '<form method="get" id="header-searchform" action="' . home_url( '/' ) . '" >
    <div>
        <div class="searchform-left"></div>
        <input class="searchform-mid clearit" type="text" name="search" id="search-header" value="Search" />
        <div class="searchform-right"></div>    
    </div>
    </form>';
    return $form;
}

add_filter( 'get_search_form', 'search_form_header' );


and this is how I'm calling my form...

<?php get_search_form('search_form_header'); ?>


And this is what my URL looks like when a search is performed (search query hello)...

/?search=hello


And all I get is the index.php?

And ideas would be truly amazing thanks. If you need more info please let me know thanks.

This is really bizarre - this has never happened before :/


I have a search.php template which consists of this...

    <?php
    /**
    * @package WordPress
    * @subpackage Example 2012
    * @since Example 1.0
    */

    get_header(); ?>


    <?php if (have_posts()) : ?>

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

    <?php the_title(); ?>

    <?php endwhile; ?>

    <?php endif; wp_reset_query(); ?>


    <?php get_footer(); ?>


this is what is in my functions.php

// SEARCH FORM HEADER
function search_form_header( $form ) {
    $form = '<form method="get" id="header-searchform" action="' . home_url( '/' ) . '" >
    <div>
        <div class="searchform-left"></div>
        <input class="searchform-mid clearit" type="text" name="search" id="search-header" value="Search" />
        <div class="searchform-right"></div>    
    </div>
    </form>';
    return $form;
}

add_filter( 'get_search_form', 'search_form_header' );


and this is how I'm calling my form...

<?php get_search_form('search_form_header'); ?>


And this is what my URL looks like when a search is performed (search query hello)...

http://www.example.co.uk/?search=hello


And all I get is the index.php?

And ideas would be truly amazing thanks. If you need more info please let me know thanks.

Share Improve this question edited Aug 13, 2012 at 18:05 kaiser 51k27 gold badges151 silver badges245 bronze badges asked Aug 13, 2012 at 17:58 JoshcJoshc 1,5207 gold badges24 silver badges41 bronze badges 2
  • Why the change from the core WordPress naming structure for the result in the URL string? As Chifliiiii suggested below, does your search result work if your change the input field to return "?s=hello" instead of "?search=hello" ? – Brent Commented Aug 13, 2012 at 19:07
  • Don't know why I change this - but yep this is the problem. – Joshc Commented Aug 14, 2012 at 8:31
Add a comment  | 

1 Answer 1

Reset to default 5

Change the form to:

<input class="searchform-mid clearit" type="text" name="s" id="search-header" value="Search" />

Check that name should be "s" as that the get attribute wordpress use for search keyword

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749220055a317368.html

最新回复(0)