WarpConduit Computing

  • Quick Tips
  • Web Design & Development
  • Graphic Design
  • Home
  • WordPress Plugins
  • Password Generator
  • About
  • Contact

Fix Redirection and Error Page On Empty WordPress Search

August 2, 2011 by Josh Hartman

I found out just recently that in some cases when you perform a blank search on a WordPress site you are redirected to the front page with an error message. If you encounter this issue simply apply the fix below, which modifies the blank search into a search for one space. This is enough to resolve the error page and land you on the search page.

Add the following code to your theme’s functions.php file to fix this annoying behavior:

if(!is_admin()){
	add_action('init', 'search_query_fix');
	function search_query_fix(){
		if(isset($_GET['s']) && $_GET['s']==''){
			$_GET['s']=' ';
		}
	}
}

if(!is_admin()){ add_action('init', 'search_query_fix'); function search_query_fix(){ if(isset($_GET['s']) && $_GET['s']==''){ $_GET['s']=' '; } } }

Filed Under: Web Design & Development Tagged With: error, redirect, search, wordpress

Comments

  1. vinhboy says

    December 6, 2011 at 8:58 PM

    thanks for the hint. this worked for me.

  2. Ronald Joseph says

    April 12, 2013 at 2:26 AM

    Thanks Your Code Work For ME

  3. sathish says

    May 30, 2013 at 6:24 AM

    Thnaks it’s awesome

  4. Baruch Youssin says

    December 15, 2014 at 7:44 AM

    I want to thank you for your 2011 page on Fixing the empty searches.
    It still works fine and your solution is much simpler than everything else I have seen on the net while the problem got worse as the empty search on my WP site does not return the list of all pages with their initial lines (according to the WP logic) but rather the FULL text of all posts and pages including all the long ones! (Apparently, it is a botched front page; I am using a static front page.)
    Thanks!

Connect

  • Facebook
  • GitHub
  • RSS
  • Twitter
  • YouTube

Recent Posts

  • Extremely Useful Applications for Web Development and IT Tasks
  • Installing BookStack Wiki on cPanel Shared Hosting
  • Media (MIME) Type Reference List

Tags

automatic base64 benchmark cache counter css deflate email font gzip htaccess html image inarray increment inline images in_array javascript jquery link list magento mailto menu metadot mysql number obfuscation opencart operating system order php random redirect rewriterule slashes software timestamp ubuntu unix upgrade url windows windows 7 wordpress

Blogroll

  • CodeIgniter
  • Fusion Forward
  • jQuery
  • Nettuts+
  • Smashing Magazine

© 2021 WarpConduit Computing. All Rights Reserved.