Create “Search By Category”

code in sidebar

<form id=”searchform” method=”get” action=”<?php bloginfo(‘url’); ?>”>
<input type=”text” name=”s” id=”s” size=”15″ />
<?php wp_dropdown_categories(‘show_option_none=Select category’); ?>
<input type=”submit” value=”Search” />
</form>

code in functions

add_action(‘pre_get_posts’, ‘search_by_cat’);
function search_by_cat()
{
global $wp_query;
if (is_search()) {
$cat = intval($_GET[‘cat’]);
$cat = ($cat > 0) ? $cat : ”;
$wp_query->query_vars[‘cat’] = $cat;
}
}


Search By Category