Advertisement
ten80snowboarder

Filter Admin by Taxonomy in Custom Post Type

Sep 11th, 2012
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.07 KB | None | 0 0
  1. /* FILTER ADMIN BY TAXONOMY IN A CUSTOM POST TYPE
  2. === http://pippinsplugins.com/post-list-filters-for-custom-taxonomies-in-manage-posts/ */
  3. function pippin_add_taxonomy_filters() {
  4.     global $typenow;
  5.  
  6.     // an array of all the taxonomyies you want to display. Use the taxonomy name or slug
  7.     $taxonomies = array('faq_topics');
  8.  
  9.     // must set this to the post type you want the filter(s) displayed on
  10.     if( $typenow == 'faqs' ){
  11.  
  12.         foreach ($taxonomies as $tax_slug) {
  13.             $tax_obj = get_taxonomy($tax_slug);
  14.             $tax_name = $tax_obj->labels->name;
  15.             $terms = get_terms($tax_slug);
  16.             if(count($terms) > 0) {
  17.                 echo "<select name='$tax_slug' id='$tax_slug' class='postform'>";
  18.                 echo "<option value=''>Show All $tax_name</option>";
  19.                 foreach ($terms as $term) {
  20.                     echo '<option value="'. $term->slug .'"'. ( isset( $_GET[$tax_slug] ) && $_GET[$tax_slug] == $term->slug ? ' selected="selected"' : '' ).'>' . $term->name .' (' . $term->count .')</option>';
  21.                 }
  22.                 echo "</select>";
  23.             }
  24.         }
  25.     }
  26. }
  27. add_action( 'restrict_manage_posts', 'pippin_add_taxonomy_filters' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement