0

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.

  • 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 Aug 13 '12 at 19:07
  • Don't know why I change this - but yep this is the problem. – Joshc Aug 14 '12 at 8:31
4

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

  • Perhaps adding a bit of explanation what was the cause and what did you change would be really helpful for some other cases. – dboris Oct 29 '18 at 8:17
  • 1
    updated @dboris – chifliiiii Oct 30 '18 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.