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.

I have a search function on my blog. If I enter a value, say 'fruits' in the search box and it doesn't match in any of the posts but it is the name of a category in the blog then I want the posts that belong to that category to be displayed.

Is it possible to amend the search functionality so it covers the searching of all categories and possibly tags in the blog too?

Many thanks.

share|improve this question

2 Answers 2

// Above the loop on your search result template:
if ( is_search() ) // Are we on a search result page?
{
    global $wp_query, $query_string;
    // now modify/filter the query (result)
    query_posts( $query_string . 'cat=1&tag=apples+apples' );
}
share|improve this answer
    
I believe that the above code will take input from the user and search for it within the apple category. What I mean is that I want the search to cover all category and tag names in the blog. So for example, if type in the search box; fruits, then although I may not have posts containing the text 'fruit' I still want posts that belong in that category to appear in the search, likewise if I type in vegetables (another category) in the search box I want post from the vegetables category to display. Apologies for not making this clear in the question, will edit it now. –  Sid May 15 '11 at 20:54
    
Why don't you simply make a drop down for all your categories and/or tags and link there? Or have you got too many cats/tags? Btw: Have you already searched the plugin repo for one that is capable of doing this? And: I edited the title of your Q for more clarity. –  kaiser May 16 '11 at 1:17

Add the "Search Everything" Plugin.

http://wordpress.org/extend/plugins/search-everything/

share|improve this answer
1  
Lone link is considered a poor answer (see FAQ) since it is meaningless by itself and target resource is not guaranteed to be alive in the future. Please try to include at least summary of information you are linking to. –  Rarst May 8 '13 at 9:33

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.