Advertisement
HaneD

Taxonomy Drop Down with hierarchical view using $terms

Nov 21st, 2012
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.39 KB | None | 0 0
  1. <?php
  2. // Equipment Category Dropdown, thanks http://frankiejarrett.com/2011/09/create-a-dropdown-of-custom-taxonomies-in-wordpress-the-easy-way/
  3. function exc_custom_taxonomy_dropdown( $taxonomy, $orderby, $order, $hierarchical, $show_count,  $name) {
  4.     $args = array(
  5.         'orderby' => 'name',
  6.         'order' => 'ASC',
  7.         'hierarchical' => true,
  8.         'show_count' => true,
  9.     );
  10.     $terms = get_terms( $taxonomy, $args );
  11.     $name = ( $name ) ? $name : $taxonomy;
  12.     if ( $terms ) {
  13.         printf( '<select name="%s" class="postform">', $name );
  14.         foreach ( $terms as $term ) {
  15.             printf( '<option value="%s">%s (%s)</option>', $term->slug, $term->name, $term->count );
  16.         }
  17.         print( '</select>' );
  18.     }
  19. }
  20. ?>
  21. <form role="search" method="get" id="equipfilter" action="<?php bloginfo('url'); ?>">
  22.         <fieldset>
  23.             <!--legend>Category:</legend-->
  24.             <?php exc_custom_taxonomy_dropdown( 'exc_equipment_cat', 'name', 'ASC', true, true, 'exc_equipment_cat'); ?>
  25. -       </fieldset>
  26.         <fieldset>
  27.             <legend>Kw Range:</legend>
  28.             <input type="text" name="kw_min" placeholder="from" value><br />
  29.             <input type="text" name="kw_max" placeholder="to" value>
  30.         </fieldset>
  31.         <fieldset>
  32.             <legend>Price Range:</legend>
  33.             <input type="text" name="pr_min" placeholder="from" value><br />
  34.             <input type="text" name="pr_max" placeholder="to" value>
  35.         </fieldset>
  36.         <input type="submit" id="filtersubmit" value="Search" />
  37.     </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement