Put this search form code where you want to search box

<form method="get" id="searchform" action="<?php bloginfo('home'); ?>/">
<input type="text" value="" name="s" id="s" />
<input type="hidden" name="search-type" value="normal" />
<input name="submit" type="submit" value="Go" />
</form>

You can give any value for search-type input which is hidden field, I used term default it’s value is normal

<input type="hidden" name="search-type" value="term" />

and put this code at the top of search.php

if(isset($_GET['search-type'])) {
$type = $_GET['search-type'];
if($type == 'term') {
load_template(TEMPLATEPATH . '/term-search.php');
}
}

term-search.php is our own file with our own desired design and template. at the top of that file add the following code:

$args = array( 'category__in' => 22 );
$args = array_merge( $args, $wp_query->query );
query_posts( $args );

$args = array( ‘category__in’ => 22 ); is our desired arguments, what results we want to in search. we can add more arguments here.

and merge this argument array with $wp_query->query, and the merged array pass into query_posts( );

and in the same file, below where we want to display search result

if (have_posts()) {

while (have_posts()) {

the_post();

post_title; ?>

post_content ?>

}

}
else{

echo "No Record Found!";
}

Advertisements