Home / category / Search categories and child
  • How to Search categories and child

    no thumbnail sorry: Search categories and child

    Adding this snippet to the functions.php of your wordpress theme will let you define a child category automatically when searching.

    ( click code to copy )

    wordpress snippet : PHP

    <form method=”get” id=”searchform” action=”<?php bloginfo(‘home’); ?>/”>
       <div id=”search”>
         <input type=”text” value=”Search… ” onclick=”this.value=”;” name=”s” id=”s” />
         <?php $categories = get_categories(‘child_of=1?);
             $catlist = ”;
         foreach ($categories as $cat) {
             $catlist.= $cat->cat_ID.’,';
         <input type=”hidden” name=”cat” value=”<?php echo “$catlist”?>” />
         <input name=”" type=”image” src=”<?php bloginfo(‘stylesheet_directory’); ?>/styles/<?php echo “$style_path”; ?>/search.gif” value=”Go” class=”btn” />
    </div><!–/search –>

    ( WordPress codex functions, hooks, in this snippet. )

    home, stylesheet, get_categories, bloginfo, stylesheet_directory,