Add filter-by-tag in the all posts admin console page

By default the ‘all posts’ page contains the following filters

  • by date
  • by category

Is there a way I can add ‘by tags’ as well ?enter image description here

Related posts

2 comments

  1. User 'restrict_manage_posts' filter to add another filter. Use the following code in functions.php

    function kc_add_taxonomy_filters() {
    global $typenow;
    
    // an array of all the taxonomyies you want to display. Use the taxonomy name or slug
    $my_taxonomies = array(  'post_tag' );
    switch($typenow){
    
        case 'post':
    
            foreach ($my_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 alignleft actions'>";
                            echo "<option value=''>Show All $tax_name</option>";
                            foreach ($terms as $term) {
                                echo '<option value="', $term->slug,'" ',selected( @$_GET[$tax_slug] == $term->slug , $current = true, $echo = false ) , '>' , $term->name ,' (' , $term->count ,')</option>';
                            }
                            echo "</select>";
                        }
    
            }
    
    
        break;
    }
    }
    add_action( 'restrict_manage_posts', 'kc_add_taxonomy_filters' );
    
  2. With absolutely no help whatsoever from this community and it’s ridiculous reputation rules, I have worked out how to amend the above code so that it works properly.

    The following code needs to go into wp-includes/functions.php. Notice that I have hardcoded the select name to be tag, which appears to be how the WP filter query string works now.

    function kc_add_taxonomy_filters() {
    global $typenow;
    
    // an array of all the taxonomyies you want to display. Use the taxonomy name or slug
    $my_taxonomies = array(  'post_tag' );
    switch($typenow){
    
        case 'post':
    
            foreach ($my_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='tag' id='$tax_slug' class='postform alignleft actions'>";
                            echo "<option value=''>Show All $tax_name</option>";
                            foreach ($terms as $term) {
                                echo '<option value="', $term->slug,'" ',selected( @$_GET[$tax_slug] == $term->slug , $current = true, $echo = false ) , '>' , $term->name ,' (' , $term->count ,')</option>';
                            }
                            echo "</select>";
                        }
    
            }
    
    
        break;
    }
    }  
    

    Then the action needs to go into your theme functions.php file (wp-content/themes/YOURTHEME/functions.php

    add_action( 'restrict_manage_posts', 'kc_add_taxonomy_filters' );
    

Comments are closed.