Seach widget sort

<?php
/*
* Plugin Name: Hyper Search
* Version: 1.0
* Plugin URI: http://hyperspatial.com
* Description: This is a simple search bar and widget
* Author: Adam J Nowak
* Author URI: http://hyperspatial.com/
*/

class HyperSearch extends WP_Widget{
function HyperSearch(){
$widget_ops = array('classname' => 'widget_hyper_search', 'description' => __( "This is a simple sidebar seach widget") );
$control_ops = array('width' => 300, 'height' => 300);
$this->WP_Widget('hypersearch', __('Hyper Search'), $widget_ops, $control_ops);
}

function widget($args, $instance){
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title']);
$category_id = empty($instance['category_id']) ? '' : $instance['category_id'];
$search_bar_id = empty($instance['search_bar_id']) ? '' : $instance['search_bar_id'];
$default_text = empty($instance['default_text']) ? '' : $instance['default_text'];
$button_name = empty($instance['button_name']) ? '' : $instance['button_name'];

# Before the widget
echo $before_widget;

# The title
if ( $title ) echo $before_title . $title . $after_title;

?>

<!-- Code Category Search -->
<div class="hyper_search" id="<?php echo $search_bar_id; ?>">
<form method="get" id="searchform" action="<?php bloginfo('url'); ?>/" class="search-form">
<input type="text" value="<?php echo $default_text; ?>" name="s" id="s" class="field" onfocus="if (this.value == '<?php echo $default_text; ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php echo $default_text; ?>';}" />
<input type="hidden" name="cat" value="<?php echo $category_id; ?>" />
<select name="category">
<?php
$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>
<?php
}
?>
</select>
<input type="hidden" name="search_query" value="yes" />
<input class="submitsearch button" type="submit" name="submit" value="<?php echo $button_name; ?>" />
</form>
</div><!-- /Code Category Search -->
<?php

# After the widget
echo $after_widget;
}

/**
* Saves the widgets settings.
*
*/
function update($new_instance, $old_instance){
$instance = $old_instance;
$instance['title'] = strip_tags(stripslashes($new_instance['title']));
$instance['category_id'] = strip_tags(stripslashes($new_instance['category_id']));
$instance['search_bar_id'] = strip_tags(stripslashes($new_instance['search_bar_id']));
$instance['default_text'] = strip_tags(stripslashes($new_instance['default_text']));
$instance['button_name'] = strip_tags(stripslashes($new_instance['button_name']));
return $instance;
}

/**
* Creates the edit form for the widget.
*
*/
function form($instance){
//Defaults
$instance = wp_parse_args( (array) $instance, array('title'=>'Custom Search', 'category_id'=>'', 'search_bar_id'=>'search_input1','button_name'=>'Submit','default_text'=>'Type Search Keywords') );

$title = htmlspecialchars($instance['title']);
$category_id = htmlspecialchars($instance['category_id']);
$search_bar_id = htmlspecialchars($instance['search_bar_id']);
$default_text = htmlspecialchars($instance['default_text']);
$button_name = htmlspecialchars($instance['button_name']);

# Title
echo '<p style="text-align:right;"><label for="' . $this->get_field_name('title') . '">' . __('Title:') . ' <input style="width: 180px;" id="' . $this->get_field_id('title') . '" name="' . $this->get_field_name('title') . '" type="text" value="' . $title . '" /></label></p>';

# Category ID
echo '<p style="text-align:right;"><label for="' . $this->get_field_name('category_id') . '">' . __('Category ID:') . ' <input style="width: 180px;" id="' . $this->get_field_id('category_id') . '" name="' . $this->get_field_name('category_id') . '" type="text" value="' . $category_id . '" /></label></p>';

# CSS ID Name
echo '<p style="text-align:right;"><label for="' . $this->get_field_name('search_bar_id') . '">' . __('CSS ID Name:') . ' <input style="width: 180px;" id="' . $this->get_field_id('search_bar_id') . '" name="' . $this->get_field_name('search_bar_id') . '" type="text" value="' . $search_bar_id . '" /></label></p>';

# Default Text
echo '<p style="text-align:right;"><label for="' . $this->get_field_name('default_text') . '">' . __('Default Text:') . ' <input style="width: 180px;" id="' . $this->get_field_id('default_text') . '" name="' . $this->get_field_name('default_text') . '" type="text" value="' . $default_text . '" /></label></p>';

# Button_name
echo '<p style="text-align:right;"><label for="' . $this->get_field_name('button_name') . '">' . __('Button Name:') . ' <input style="width: 180px;" id="' . $this->get_field_id('button_name') . '" name="' . $this->get_field_name('button_name') . '" type="text" value="' . $button_name . '" /></label></p>';
}

}// END class
function HyperSearchInit(){ register_widget('HyperSearch'); }
add_action('widgets_init', 'HyperSearchInit');
?>

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">
<?php
$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>
<?php
}
?>
</select>
<input class="submitsearch button" type="submit" name="submit" value="Search" />
</form>

Display search result count

<!--test post count-->

<h2 class="pagetitle">Search Result for <?php /* Search Count */ $allsearch = &new WP_Query("s=$s&showposts=-1"); $key = wp_specialchars($s, 1); $count = $allsearch->post_count; _e(''); _e('<span class="search-terms">'); echo $key; _e('</span>'); _e(' &mdash; '); echo $count . ' '; _e('articles'); wp_reset_query(); ?></h2>

<!--/test post count-->