When there is no value for parameter "s" , it redirects automatically to homepage. Instead of this , I want to show all the information from my custom sql query. how can i do this??

2 Answers 2


You can pass s=%20 as your search string, but thats kinda hackish.

If what you are trying to achieve is to use your search.php template but with "controled" search results, consider using this:


global $query_string; // fetch query string being used
query_posts($query_string . '&posts_per_page=20') // add your terms to it.


Create a custom search form and use <input type="hidden" name="s" value="whatever" /> in it, of course along with your usual search form (at the least an <input type="text" name="search" />).

Then, $_GET['s'] will always be set. Remember to create a custom search page running your custom query (with $_GET['search'] for the search terms), or you will find yourself always searching for the placeholder value you put in $_GET['s'].

You can see a live example of a solution similar to this at my site Allt du behöver (unfortunately in Swedish but I think you can figure out how it works anyways).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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