How did I not post this yet? If you have taxonomies tied to your Custom Post Types then you probably want those taxonomies to show up in the admin listing of those post types. Here is the code needed to do that.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
/** * Show the taxonomies on the admin page */ add_filter( 'manage_taxonomies_for_post-type_columns', 'jb_show_cpt_taxonomy' ); function jb_show_taxonomy_taxonomy( $taxonomies ) { $taxonomies[] = 'tax-slug'; return $taxonomies; } /** * Setup a dropdown to allow filtering by taxonomy in the admin */ add_action( 'restrict_manage_posts', 'jb_add_taxonomy_filters' ); function jb_add_taxonomy_filters() { global $typenow; // must set this to the post type you want the filter(s) displayed on if( $typenow == 'post-type' ){ $taxonomies = array('tax-slug'); foreach ($taxonomies as $tax_slug) { $tax_obj = get_taxonomy($tax_slug); $tax_name = $tax_obj->labels->name; $terms = get_terms($tax_slug); if(count($terms) > 0) { echo "<select name='$tax_slug' id='$tax_slug' class='postform'>"; echo "<option value=''>Show All $tax_name</option>"; foreach ($terms as $term) { echo '<option value='. $term->slug, $_GET[$tax_slug] == $term->slug ? ' selected="selected"' : '','>' . $term->name .' (' . $term->count .')</option>'; } echo "</select>"; } } } } |
This has been posted on various sites around the web so I cannot take credit for it, but I need it all the time and figured I would stick it here so I can find it easier.