Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // registers each of the taxonomy filter drop downs
- function ecpt_fbt_add_taxonomy_filters() {
- global $typenow; // the current post type
- $taxonomies = get_taxonomies('','objects');
- foreach($taxonomies as $taxName => $tax) {
- if(in_array($typenow,$tax->object_type) && $taxName != 'category' && $taxName != 'tags') {
- $terms = get_terms($taxName);
- if(count($terms) > 0) {
- //Check if hierarchical - if so build hierarchical drop-down
- if($tax->hierarchical) {
- $args = array(
- 'show_option_all' => 'All '.$tax->labels->name,
- 'show_option_none' => 'Select '.$tax->labels->name,
- 'show_count' => 1,
- 'hide_empty' => 0,
- 'echo' => 1,
- 'hierarchical' => 1,
- 'depth' => 3,
- 'name' => $tax->rewrite['slug'],
- 'id' => $tax->rewrite['slug'],
- 'class' => 'postform',
- 'depth' => 0,
- 'tab_index' => 0,
- 'taxonomy' => $taxName,
- 'hide_if_empty' => false);
- $args['walker'] = new Walker_FilterByTaxonomy;
- wp_dropdown_categories($args);
- } else {
- echo "<select name='".$tax->rewrite['slug']."' id='".$tax->rewrite['slug']."' class='postform'>";
- echo "<option value=''>Show All ".$tax->labels->name."</option>";
- foreach ($terms as $term) {
- echo '<option value="' . $term->slug . '"', $_GET[$taxName] == $term->slug ? ' selected="selected"' : '','>' . $term->name .' (' . $term->count .')</option>';
- }
- echo "</select>";
- }
- }
- }
- }
- }
- add_action( 'restrict_manage_posts', 'ecpt_fbt_add_taxonomy_filters', 100 );
- /**
- * Create HTML dropdown list of Categories.
- *
- * @package WordPress
- * @since 2.1.0
- * @uses Walker
- */
- class Walker_FilterByTaxonomy extends Walker {
- var $tree_type = 'category';
- var $db_fields = array ('parent' => 'parent', 'id' => 'term_id');
- function start_el(&$output, $category, $depth, $args) {
- $args['selected'] = get_query_var( $args['taxonomy'] );
- $pad = str_repeat(' ', $depth * 3);
- $cat_name = apply_filters('list_cats', $category->name, $category);
- $output .= "\t<option class=\"level-$depth\" value=\"".$category->slug."\"";
- if ( $category->slug == $args['selected'] )
- $output .= ' selected="selected"';
- $output .= '>';
- $output .= $pad.$cat_name;
- if ( $args['show_count'] )
- $output .= ' ('. $category->count .')';
- if ( $args['show_last_update'] ) {
- $format = 'Y-m-d';
- $output .= ' ' . gmdate($format, $category->last_update_timestamp);
- }
- $output .= "</option>\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment