I wanted to make a page to search a single category. Turns out it’s already possible; you just need to tweak wordpress a little.

First, copy your search form and paste it into a new page. It’ll look something like this:

<form id=”searchform” method=”get” action=”/index.php”> <small>Search:</small> 
<input type=”text” name=”s” id=”s” size=”25″ class=”nav_textarea”/></form>

Now, go look in the wp_categories table in your wordpress database (you probably have something called phpMyAdmin in your cpanel on your webhost; click that, go to tables, choose wordpress, click wp_categories, click browse). Find the category you’re interested in, and find the id. In my case, I was looking for my energy crisis category, which has an id of 12. Then, add a line to your new search page:

<form id=”searchform” method=”get” action=”/index.php”> <small>Search:</small> 
<input type=”hidden” name=”cat” id=”cat” value=”12″/>
<input type=”text” name=”s” id=”s” size=”25″ class=”nav_textarea”/></form>

Save the page, and try it out. Be warned that the search is “sticky”; if you have a search elsewhere on your blog, e.g. on the header, it will “remember” the category that you started the search from. You have to go back to the front page and search from there to reset it (I’m sure you could come up with a code hack to do so if it mattered.)



Related Leave a Comment