The Ultimate WordPress Search

If you’ve been following the story thus far, I’ve been working at refining our search on Streetsblog.  The standard WordPress search only returns results ordered by date, so my first step was to integrate Google Custom Search with Streetsblog.  This works beautifully and should meet the needs of most readers, but soon our editors realized that they’d also like the option of sorting by date.

I played around with biasing the Google search results by date.  This worked fine but, unfortunately, Google searches all site content, including sidebar content and category drop-down lists, when returning results.  So, if you searched for something like a category name, you would essentially end up with a list of all blog posts in reverse chronological order, which is quite useless.

What our editors really wanted was to be able to revert back to the original WordPress search which only searches blog post content.  So I spent some time integrating it with the Google Custom Search interface.  I ended up producing an almost exact replica of the styles and behavior used by Google.  I managed to pull in post thumbnails, to highlight the search term in results, etc.

So now we can search for “bike lanes” by date or by relevance and get useful results for both.  And for anyone else who wants to do this, here’s the code.


Comments are closed.