php - wordpress search for only single category -


i creating news website @ index page listed news categories created 1 more category 1 of news section recipes want creating search form section filter search recipe category,how can wanted know created normal search.php page per wordpress standard code filter news through out theme. please me out.

here 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 &hellip;', '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 implement function catch search defining category in category__in array.

global $wp_query; if(is_search()) :     $cat = array(         'category__in' => array(5) // 5 id of music category     ); $args = array_merge( $wp_query->query, $cat ); endif; query_post($args); 

or

you way through hidden field - value 22 category

<form method="get" id="search form" action="/"> <div> <input type="text" value="" name="s" id="s" /> <input type="hidden" value="22" name="cat" id="scat" /> <input type="submit" id="search_submit" name="search" value="search"/> </div> </form> 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -