WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
    
are you want to replace categories dropdown filter with tags? – Anjum Sep 4 '13 at 18:23

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' );
share|improve this answer

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' );
share|improve this answer

protected by Community Feb 27 at 11:17

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.