WordPress Single Category Search

Sometimes it comes in handy to make the search form on a blog only return results from a single category. It’s actually quite simple.
1. Find the category ID
First we need to find the ID of the category that we want to search. We can find that by going to Posts>Categories and hovering over the category we want to search in the categories list on the right side of the page. When we hover the mouse over a category, we’ll see something like this in the status bar (usually the bottom left corner of the browser):
…/wp-admin/categories.php?action=edit&cat_ID=3
As you can probably see, the 3 at the end is the category ID. That number is all we need to know.
2. Edit the searchform.php file
We just need to find this line in the searchform.php file of the theme:
<form method="get" id="searchForm" action="<?php bloginfo('home'); ?>/">
and add this hidden field immediately after it:
<input type="hidden" name="cat" id="cat" value="3"/>
3. Apply the category ID
Now we need to make sure that we change the value of the hidden field to the category ID we found in step one. For example, if the category we chose had an ID of 12, then the hidden field would look like this:
<input type="hidden" name="cat" id="cat" value="12"/>
It’s that easy! If you have any questions, feel free to post them in the comments section below.
Image by rockmixer