You shouldn't have to be an expert to be safe on a computer.

Home

Guides

Seminars

Tips and Tricks

Log in

Jsearch – WordPress Multiple Category, Tag, and Term Search

Monday, July 5th, 2010 (94 comments)

About the only big disappointment with WordPress that I've ever had is that you can't do any kind of advanced searching and none of the available plugins seem to get the job done either.

After I put together my own little hack for searching in multiple categories, I had the idea to make something more advanced that handled tags and terms as well. It was a bit weak, but I learned a lot.

For the last year and longer, I've had requests and suggestions for features such as making it widget compliant and capable of searching custom fields.

I'm happy to announce that after over 100 hours of development, I have finally completed the first ever Jsearch plugin. Each prior version was just a code hack, but this one handles pretty much everything I've ever been asked to include.

Features

Easy Search

Allows your visitors to do advanced query building using a slick and simple interface. For example, they could:

  • Search for items in the beach or mountain categories with the resort keyword as long as it didn't contain the complete dump tag.
  • Search for any posts, pages, or both that contain the word monster in the title.
  • Find anything tagged with Michael Jackson that was also in the Photo Gallery category that did not include the keyword Presley

Clearly, you can get very, very specific about what you're looking for.

Searching titles containing FACEBOOK, but not FOUNDER
Searching titles containing FACEBOOK, but not FOUNDER

Strong Administrative Control

In the Jsearch administration screen, you can set default options for most aspects of the search as well as whether your visitors can change that option or not. Nearly every control can be hidden preventing users from changing your preferred way of searching.

The Jsearch control panel in the WordPress dashboard
The Jsearch control panel in the WordPress dashboard

Customizable Results

There are 2 default listing styles (Jsearch default and WordPress default) and 3 custom templates that can be configured as needed.

Jsearch default
Jsearch default
WordPress default
WordPress default

This allows you to style and customize your results just like you would for any WordPress template. You can also have multiple views in the same WordPress installation depending on the need. For example, for normal results on my City of Heroes fan page, I like the results to be the Jsearch Default, but then I used the Custom1 template and customized it to show a thumbnailed list when browsing the image gallery.

Using the custom templates to do a thumbnail search (example only)
Using the custom templates to do a thumbnail search (example only)

Note that the custom template I used to make the thumbnails is included as Custom1 as a sample, but will not work on your page since I use a plugin that you don't have in it. It is only included so you can see how the code can be done (if you want to see it working, go here: Jordan's Town Gallery).

Full URL Customization

Every aspect of the jsearch control (and a few others) can be set via the URL. For example, the thumbnail search I just mentioned is triggered by loading the search page with the following variables in the URL string:

http://www.jordans-town.com/jsearch/?paged=295&cat_all=106&ppp=24 &control_vis=min&results_type=custom1&order=asc

  • &cat_all=106 – 106 is the id of the Gallery category. This restricts all results to gallery photos only
  • &ppp=24 – Sets the number of posts per page to 24
  • &control_vis=min – Minimizes the Jsearch control on first page load (this is a new feature that makes the control stay out of the way until it's needed).
  • &results_type=custom1 – Sets the results template to Custom1
  • &order=asc – Sets the results to show in ascending date order (WordPress default is descending order). I do this for my gallery so that when you bookmark a page, new additions don't change the photos that are on page 295 for example.

Using this method, I can have the standard defaults as set in my administration panel, but create tailored views on the fly using nothing more than a link with some variables.

Installation

If you want to see how it works first, just try it out. Otherwise, download it and try it here.

Once downloaded, follow these instructions:

  1. Unzip the plugin to your plugins/jsearch folder like this:
    Just like every other plugin really...
    Just like every other plugin really...
  2. Copy the jsearch_template.php file to your current theme's directory so it's available to your theme to be selected as a page template.
  3. Create a new page using the Jsearch template.
  4. Click on the "Jsearch Config" link in the plugins area on the left menu in the WordPress dashboard. On that page, select the page you just created in the drop-down list (so the plugin knows which page is using the template) and click "SAVE" at the bottom of the settings page.
  5. Mess with the other settings if you wish, but you're basically done (if you do change something, remember to click "SAVE" at the bottom to save the changes).
  6. (Optional but recommended) Replace the normal search widget in your sidebar with the Jsearch equivalent. This customized search box will feed directly to the Jsearch page and contains an "Advanced Search" link that will go directly to the search page without having to enter any terms first.

NOTE! I know there's an error where even after setting and saving the Jsearch target page, you'll still see a notice saying you haven't, but that will go away on it's own. I don't know what causes it but when I do, I'll put a fix in for it.

Support the Geek

If you hate ads as much as I do, please consider supporting us by donating or browsing our recommended products


Recommended Products and Services
Quick Tips:

Jsearch - Wordpress Multiple Category, Tag, and Term Search

Jsearch, the most complete search plugin available for Wordpress. Handles multiple categories, tags, and keywords all at the same time. Widget enabled!

[Click for full description]

Get File Path to Wordpress Theme

Here's a tip to get the file path to your current Wordpress theme.

[Click for full description]

Hack Wordpress to Make Postnames Always Editable

When using ordinary permalinks, you're blocked from editing the postname when doing posts and pages. This is senseless and must be stopped!

[Click for full description]