Allowing null search with Relevanssi

I love the Relevanssi plugin for WordPress. It’s an easy way to power up the, frankly lame, native WordPress search.

By default the plugin will return no search results if no search term is given. Makes sense. But what if you are searching by other criteria too, and want to allow the search term input to be empty?

I’m building a custom job search for a client. There will be a ‘Search jobs’ form in the sidebar and the user will be able to search by term and region. The region is a taxonomy which the user selects from a drop-down. The form looks like this:

 

Screen Shot 2014-10-07 at 10.17.10

 

You have to tell Relevanssi to listen for the region query. Here’s how:

That works great if you enter a search term and a region. Yay! But it still doesn’t allow an empty search term. With some help from Mikko, the plugin author, I got it working. Here’s the code to fix it (and the actual form code I used):

HTH,

Keith

WordPress SEO: 10 tips for better search rankings

FREE E-book. Learn the basics of WordPress SEO and how to improve the key metrics
  • We won't sell your address to anyone. We hate spam too.
View my portfolio Get in touch

3 Responses to “Allowing null search with Relevanssi”

  1. Shawn

    Hello, I am trying to follow this. I have a post type “listing” with a Taxonomy “location” and one of my categories is “Richmond”. I am trying to implement the same thing, as if the search form is empty then it brings up all listings in the Richmond location.

    I am trying to use the code above you posted but I can’t figure out how to use my info and replacing it with yours.

    Could you, or would you mind helping me out with this?

    Shawn

    Reply

Leave a Reply