Search results - or not (8 posts)

  1. elfin

    Posted 7 years ago #

    This also affects earlier versions. If I try and search a wordpress Blog, but forget to enter any terms I end up... on the home page. Surely on a Search, even if blank, I should be redirected to the search results page?

    I've just sent someone this code (not sure if it's fully correct) as a suggested interim fix:

    function blank_search($query){
    	global $wp_query;
    	if (isset($_GET['s']) && $_GET['s']==''){
    		$wp_query->set('s',' ');
    	return $query;

    Is this even possible to correct for a future release?

  2. mrmist
    Forum Janitor
    Posted 7 years ago #

    In the 2.7 beta default theme after a no results search it redirects to a page saying

    "No posts found. Try a different search?"

    and listing your criteria.

    So I'd say it is fixed for 2.7.

  3. elfin

    Posted 7 years ago #

    That's strange because in my copy it doesn't! But I'm testing locally and occasionally that doesn't always return the same results.

    Can someone else confirm/deny the result of submitting a blank search.

  4. mrmist
    Forum Janitor
    Posted 7 years ago #

    My mistake - I thought you meant "a search that returned no results" rather than "a search for nothing".

    If you just press enter in the search box it does indeed refresh to home.

  5. elfin

    Posted 7 years ago #

    well at least its not just me!

  6. MikeCherim
    Posted 7 years ago #

    You should make a plugin Rich ;)

  7. elfin

    Posted 7 years ago #

    well turning that into a plugin is ok, but it isn't an elegant solution. I'm forcing the search into searching for a single blank space. This doesn't allow us as developers to grab the fact that no search terms were entered. So I'd have to extend things a little bit to make it a bit more practical.

  8. elfin

    Posted 7 years ago #

    currently testing a better fix for this over on permanent tangent.

    However it requires an addition to your themes search.php so I still couldn't solve it as a pure plugin.

Topic Closed

This topic has been closed to new replies.

About this Topic