Good day fine wordpress gurus,

I'm having a tough time writing a function that handles the search in a couple of user-selected categories. The way I'm presenting the categories is through the old get_categories method and I'm iterating through the array in order to build a category tree with checkboxes (client requirement).

So what I need is a hint of how to get the search in such a way that it includes the search term and the cat_ID's that the user selected in order to bring the relevant results.

PS: I already checked out Wordpress Multiple Category Search this link, and I didn't find anything useful. so please help.

1 Answer 1


Sounds like something Relevanssi could handle. With Relevanssi, you'd have the checkboxes to choose the categories. Then, you'd write a function to hook on 'relevanssi_modify_wp_query' filter, where you'd read the checkboxes and convert them to a comma-separated list of category ID's. That you would store in $wp_query->query_vars['cats'] and hey presto, Relevanssi gives you relevant results in those categories.

I think the same idea might work with default search, actually, but instead of 'cats' you'd use 'cat' and instead of 'relevanssi_modify_wp_query' you'd need another way to modify the $wp_query.

  • Yes, thank you Mikko, I finally went down the relevanssi route and I'm setting the value for cats through some javascript which builds an array from the values of the checkboxes.
    – adioporanu
    Commented Sep 17, 2012 at 5:08

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.