I have a pretty complex search feature I would like some advice on.

I need to build a pretty advanced custom search in Wordpress and would like to get your opinion on how I can achieve it. I've made a lot searches for current plugins but nothing that really caters for this. I've also looked at creating custom functions (function.php)

It works like this:

  • Input keywords into a text field,
  • these can then be added to a keyword 'bank'.
  • you can then select from drop down the industry to search in (post category maybe).
  • Then another drop down for country
  • and a final one listing the months published (september 2012, october 2012 etc)

Once the search button is hit, I need to display results based on relevance.

  • So the top result would say 'Matched 4 filters: keyword, industry, country & date'.
  • After there are no more results matching all 4 search options it displays any that match 3,
  • then 2
  • and eventually just displaying keyword searches.

So the search is essentially

  • a text field to hold all keywords,
  • 3 drop down select fields
  • and then the search button.

I'm not convinced this is the best method to store a list of keywords given by the user before launching the search. May need to think alternatives.

Hope it makes sense so far.


My knowledge of customizing wordpress is pretty good but I've never created a search before. I would like to ask for opinions for tackling this as a solution.

Hope you can help.



1 Answer 1


There's a few ways you could do this. I once wrote some extended code to integrate Apache Solr with WordPress search and BuddyPress and that added a lot of power. With something like Apache Solr you can customize weight and do some interesting things. Solr is a full fledged search engine and you will need to run a server for it (or purchase a cloud based instance). Check out the Solr for WordPress plugin as a starting place if that seems like a good route for you. The biggest negative here is that you have to run Solr and you'll need to learn a bit about it before it will have the power that you need. You will be amazed however at the speed and complexity that Solr can do.

The next most powerful way to accomplish what you're looking for is writing your own search query functions using the $wpdb object. This is not an easy option but the most likely to produce the results that you are looking for. The other caveat with this option is that you'll have to keep an eye on changes to the WordPress MySQL structure since it may affect your queries. Start with something like this and then you'll need to research MySQL joins in order to get all the queries the way that you want:

global $wpdb;
$query = $wpdb->prepare("
  FROM $wpdb->posts
  WHERE post_title LIKE %s
", $search); 

Another more limited solution is that you could use add_filter('posts_search', 'my_custom_search_function') to build a filter that changed the posts results search as you desired but this may not give you everything you need/want.

As a final solution you could look into the wp-types.com plugin Views and see if it's query building function would work for you. I'd guess that a custom taxonomoy and/or custom fields (via the Types plugin) might be able to accomplish your goals here.

  • Solr is definitely a good try, as any other Lucene-based search engine.
    – david
    Oct 30, 2012 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.