WordPress 3.5 admin columns for custom taxonomies
WordPress 3.5 is here!! If you haven’t played with it yet, go get it!
I’m proud to be listed as a contributor on this release and want to highlight a new feature geared towards developers that I helped work on. If you have checked the register_taxonomy() codex page recently, you may have noticed a new optional argument, ‘show_admin_column.’
From the codex:
show_admin_column
(boolean) (optional) Whether to allow automatic creation of taxonomy columns on associated post-types.
Default: false
As stated, this new argument allows easy registration of taxonomy columns on post (and custom post type) list table screens much like the default tags’ and categories’ columns.
This should make plugin and theme developers happy as they’ll no longer need to build these columns manually.
The new argument in action:
// hook into the init action and call create_activity_taxonomies when it fires
add_action( 'init', 'create_activity_taxonomies' );
// create taxonomy, "fitness-type" for the post type "activity"
function create_activity_taxonomies() {
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
'name' => _x( 'Fitness Types', 'taxonomy general name' ),
'singular_name' => _x( 'Fitness Type', 'taxonomy singular name' ),
'search_items' => __( 'Search Fitness Types' ),
'all_items' => __( 'All Fitness Types' ),
'parent_item' => __( 'Parent Fitness Type' ),
'parent_item_colon' => __( 'Parent Fitness Type:' ),
'edit_item' => __( 'Edit Fitness Type' ),
'update_item' => __( 'Update Fitness Type' ),
'add_new_item' => __( 'Add New Fitness Type' ),
'new_item_name' => __( 'New Fitness Type Name' ),
'menu_name' => __( 'Fitness Type' ),
);
register_taxonomy( 'fitness-type', array( 'activity' ), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'fitness-type' ),
) );
}
Another key addition is the “manage_taxonomies_for_{$post_type}_columns” filter. This allows developers to add a taxonomy column to a post type outside of the register_taxonomy() function:
Example:
add_filter( 'manage_taxonomies_for_activity_columns', 'activity_type_columns' );
function activity_type_columns( $taxonomies ) {
$taxonomies[] = 'activity-type';
return $taxonomies;
}

Jon Brown 3:10 am on December 12, 2012 Permalink | Log in to Reply
Cool addition, I had no idea this was coming, thanks for highlighting it.
Justin Sternberg 3:38 am on December 12, 2012 Permalink | Log in to Reply
It’s been a bit under the radar with all the amazing new features dropped in 3.5, but I’m glad to give it a bit of a push.
Frank Bültge 7:19 am on December 12, 2012 Permalink | Log in to Reply
Very usefull; time to dont use the custom class for doing this. Thanks.
cdils 2:21 pm on December 12, 2012 Permalink | Log in to Reply
Yes! Thank you for highlighting this. Was just winging these columns this week with some Yoast code. Digging this!
Lisa Sabin-Wilson 3:22 pm on December 12, 2012 Permalink | Log in to Reply
This is really good stuff Justin! show_admin_column makes life a bit easier and cleaner.
Justin Sternberg 3:32 pm on December 12, 2012 Permalink | Log in to Reply
Thanks a lot Lisa! Any code that makes life easier and cleaner is fine by me.
cdils 4:07 pm on December 12, 2012 Permalink | Log in to Reply
Was playing with this and thought I’d share…If you want to add more than one taxonomy column, add another line with syntax:
$taxonomies[] = ‘second-taxonomy’;
Where {$post_type} is your CPT name
/**Add columns to CPT admin page */
add_filter( ‘manage_taxonomies_for_{$post_type}_columns’, ‘{$post_type}_type_columns’ );
function {$post_type}_type_columns( $taxonomies ) {
$taxonomies[] = ‘first-taxonomy’;
$taxonomies[] = ‘second-taxonomy’;
return $taxonomies;
}
Thanks again, Justin. Awesome stuff. Is there a filter for includling a custom field as a column?
Justin Sternberg 4:30 pm on December 12, 2012 Permalink | Log in to Reply
No there is not. Post meta can take on many forms, so to try to pin down a specific column use-case would undoubtably rule out a large portion of users. But honestly building custom columns for simple forms of post-meta is not too difficult.
mor10 4:30 pm on December 12, 2012 Permalink | Log in to Reply
Excellent! The old way was so verbose and clunky. This looks much cleaner and more approachable.
Alex Mills (Viper007Bond) 8:39 pm on December 12, 2012 Permalink | Log in to Reply
This is great, thanks! Time to rip a bunch of manually added columns out of my plugins that use custom taxonomies!
RiccardoB. 9:09 pm on December 15, 2012 Permalink | Log in to Reply
Less code, same result. Useful!
Maor Chasen 9:38 am on December 20, 2012 Permalink | Log in to Reply
Lovely! Can’t wait to give it a spin!