Adding Tags Filter to the Posts List

By default, WordPress does not ship the tag filter capability to its posts list whilst, in many cases, we need it to quickly access to the content type we have classified.

To do so, add the following codes:
<?php

/***********************************
* Function to add filter by tags
* in the posts list
*/

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’ );

To your functions.php

Then you’ll have this filter option right in your posts list:

Add Tag Filter in Posts List

About Author:

I am a WordPress lover. I make my living by using WordPress.

Leave A Comment

Your email address will not be published. Required fields are marked *