Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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.

share|improve this answer
    
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 Sep 17 '12 at 5:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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