Refine search by category

//Add this to the search.php file, just above the wordpress loop
<?php $search_category = $_GET['category']; ?>
<?php query_posts('&cat=' . $search_category); ?>

//Add this wherever you want to display the search form

<form method="get" id="searchform" action="<?php bloginfo('url'); ?>/" class="search-form">
<input type="text" value="Search" name="s" id="s" class="field" />
<select name="category">
$categories = get_categories();
foreach ($categories as $cat){ ?>
<option value="<?php echo $cat->cat_ID; ?>" <?php if($cat->cat_ID == 3) echo 'selected="selected"'; ?>><?php echo $cat->cat_name; ?></option>
<input class="submitsearch button" type="submit" name="submit" value="Search" />


You must be logged in to post a comment.