Focusing Search

Improving the built in search
functionality of WordPress

By Flynn O’Connor - @thoronas

My name is
Flynn O’Connor

  • Developed WordPress themes for 4 years.
  • Lead developer at Forge and Smith

Search is like any other WP_Query

This means we can use any of the parameters available to WP_Query for our search query.

  • Custom Post Types
  • Taxonomies
  • Meta values

Take Control

Inputs added to the form can control the query. But they must match the corresponding query parameters.

The results

what your form looks like


What your query string looks like


Say hello to my little friend


This action will alter the query before it is run.
With this you can do complicated search queries
involving taxonomies and meta values.

Search using custom meta data

Filter posts based on custom post meta.

If you have large chunks of content in custom meta use the "like" comparative parameter

Hide Content

Sometimes you don't want specific content to be searchable. You can specify that content in several ways.

  • Hide pages or posts
  • Hide categories
  • Hide entire post types

Changing the structure

If you allow search for multiple post types
you will probably have different
structure/layout for your content.

Your content should be consistent

If your content looks like this on your site.


But your search results look like this


It is a bad user experience.

The elephant in the room

You can sort search results by:

  • Date
  • Name
  • Menu Order
  • Random

The major problem with the built in WordPress search: search results can’t be sorted by relevance
to the search term.



Default search results ordered by relevance instead of date.

Non relevant
search results


Relevant search results


Control what gets searched

Without touching the code you can enable searches within:

  • Custom Post Types
  • Taxonomies
  • Custom Meta Fields

Allows keyword searches in all of the above

Plays nice with others

Because we are using pre_get_posts and passing valid query variables via form elements all of our custom search queries will work with Relevanssi right out of the box.

Moar powar!

If you want more control over your results
or search analytics.

  • Elastisearch
  • Swiftype

Elastic Search

An open source search and analytics engine. Installs on your server. Provides analytics, discover popular search terms.


  • Scalability
  • Real time analytics
  • Open Source
  • Reduce load on SQL server
  • Fast


  • Difficult to set up for non-devs
  • Managing indices can be complex

Cloud based

Services like provide a cloud based Easticsearch for WordPress sites. Easier for non-devs to set up. Removes some of the complex configuration required.

Provides an easy to use plugin WP-Elasticsearch for simple integration through WordPress dashboard.


Cloud based search service, provides easy to implement search alternative.


  • Easy to set up.
  • Dashboard allows you to customize search results.
  • Detailed analytics


  • Limited free service, pay for all features
  • Custom search forms don't play well out of the box

Thanks for listening!


Contact me:
Twitter: @thoronas

WordCamp Vancouver 2013

August 17th


Tickets on sale June 17th!

Speaker submissions until July 3rd.

Social Media galore!

Follow us on: