WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
// 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

Your Answer


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.