WordPress search without a keyword

May 21, 2012 | PHP, Themes, Time Savers, Tutorials, Wordpress | 0 comments

The WordPress search is nice and extensible in many ways except for the option to search with no keywords. Why would you want to do that you ask? Well what if you wanted to search multiple taxonomies at once as a way of drilling down using search criteria with optional keyword as opposed to being forced to use it regardless of relevance.

For instance you might want to search for an event with location, price and age range as taxonomies.. using the WordPress template system this isn’t possible without bodging so you would use the search template to host your own query_posts call to make it happen.

So you use the search form included with most sites and add a taxonomy dropdown or two to get the required fields in there. You submit the form thinking it will go to the search page and then….404. Not good really. This is because unless $_GET[‘s’] is set and not empty WordPress will not recognise it as a search. This code added to your functions.php file in your theme is a simple way of using the search.php template for any page submitting a form with ‘s’ as a field in the query string (which we can safely assume is a search).

function sb_activate_search() {
    if (isset($_GET['s'])) {
        include (TEMPLATEPATH . '/search.php');

add_action('template_redirect', 'sb_activate_search');

A Donate Button!



  1. How to create a WordPress location based search | Tortoise IT - […] http://www.sean-barton.co.uk/2012/05/wordpress-search-keyword […]

Submit a Comment

Your email address will not be published. Required fields are marked *

CommentLuv badge

Divi United

About this site and Sean Barton

Picture of Sean
Sean Barton is a Freelance PHP Website Developer in Crewe, Cheshire. He is a Wordpress and CMS/Framework specialist.
This site was set up in 2008 as a tutorial and scripting resource for the PHP language and Wordpress.
Find out more about Sean on the About Me page or use the Hire Me page to get in touch. For more information about Sean's work take a look at the Portfolio

Our Services

  • Wordpress plugin/theme development
  • Divi specialist
  • Ecommerce (Woocommerce, WPSC, Shopify, Magento)
  • PSD to Wordpress theme conversion (Responsive)
  • Website design work (Banners, Logos, Full Site, etc)
  • Website analysis (security, usability, SEO)
  • API Integrations (InfusionSoft, SalesForce, Ontraport, Customer Thermometer, etc..)
  • Wordpress consultancy & expert advice
  • Crisis support
  • Website hosting

The main services offered are Wordpress based although we do a great deal of technical programming for bespoke systems. From troubleshooting, extending frameworks, finding bugs to writing them from scratch.

Find out more by looking through our past projects or get a quote.

Be the first to hear about new products/updates!

This is a mailing list for those people interested in being told when we release a new product (Divi plugin or Theme).

We shall also use this list to let you know about product updates and releases.

You have Successfully Subscribed!