Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Taxonomy Drop Down with hierarchical view using $terms

By: HaneD on Nov 21st, 2012  |  syntax: PHP  |  size: 1.39 KB  |  views: 64  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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>