• My search form currently returns the posts page if no search term is entered.

    I want it to instead return the search page (url is /search/).

    Can I do this by changing my form code?

    <form method="get" action="<?php bloginfo('url'); ?>/">

Viewing 4 replies - 1 through 4 (of 4 total)
  • What theme are you using? Where did you download it from?

    Thread Starter gulliver

    (@gulliver)

    Thanks.

    It’s a cobbled-together effort of my own doing. 🙂

    Another search shows this issue happens elsewhere, and there’s a suggested fix of adding

    value="<?php if(trim(wp_specialchars($s,1))!='') echo trim(wp_specialchars($s,1));else echo ' ';?>"

    to the form. Although I don’t pretend to understand, it seems to work.

    (When I first searched this ages ago, I never found anything; clearly I should have searched again before posting today.)

    Sounds like your search.php script isn’t handling searches with no results correctly. Have a look at the way in which the 2014 theme’s search.php handles it.

    Thread Starter gulliver

    (@gulliver)

    Thanks.

    As for 2014 handling… I’ll say ‘badly’ – it returns the posts page, with what looks to be full posts.

    Since originally posting, I found a core.trac.wordpress thread from years ago in which the issue is noted and met with a response of ‘itching to close this as won’t fix…you’re describing the expected behavior, which works fine, so this technically is an enhancement. and then, it seems extremely specialized.’

    Hhhmmm… I agree with others who suggested ‘Hitting the Search button should take you to a Search result page; a blank search string _should_ take you to the search page and state “No posts found. Try a different search?” as it does when you enter an invalid search.’

    Anyway, I’m grateful for the stuff WP does well and so shall stop moaning about other issues.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Recode so blank search returns search page.’ is closed to new replies.