I am creating a news website at index page i listed all news by categories i created 1 more category for one of my news section that is recipes now what i want is i am creating a search
form for that section only that filter the search for only recipe category,how can i do that i wanted to know basically i created a normal search.php page as per wordpress standard code
that filter news from through out the theme.
please help me out.
here is a code in form page:
<div class="search_box">
<form method="get" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<div class="input-group">
<input type="text" class="form-control search-bar eng my_control" name="s" id="search" placeholder="<?php echo esc_attr_x( 'Search …', 'placeholder', 'dastak' ); ?>" value="<?php echo esc_attr( get_search_query() ); ?>" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"/>
<span class="input-group-btn">
<input type="submit" class="search-submit btn my-btn" value="<?php echo esc_attr_x( 'Search', 'submit button', 'dastak' ); ?>">
<!-- <button class="btn my-btn" id="searchsubmit" type="button"><span class="glyphicon glyphicon-search"></span></button> -->
</span>
</div><!--input group-->
</form>
</div><!--search box-->
<div class="clearfix"></div>
You could implement a function to catch the search but defining the category in the category__in array.
OR
You could do it this way through the hidden field – value 22 is the category
You have to hook the WordPress WP_Query global instance and add whatever conditions you want.
Start reading about preg_get_posts WordPress hook. You’ll find two examples about categories.