Skip to content

Instantly share code, notes, and snippets.

@nacin
Created November 5, 2011 20:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nacin/1342010 to your computer and use it in GitHub Desktop.
Save nacin/1342010 to your computer and use it in GitHub Desktop.
Sample Taxonomy Column on edit.php
<?php
add_action( 'init', function() {
register_taxonomy( 'some-taxonomy', 'post', array(
'show_ui' => true,
'rewrite' => false,
'public' => true,
'labels' => array(
'name' => 'Some Taxonomy',
'singular_name' => 'Some Taxonomy',
)
) );
} );
add_filter( 'manage_post_posts_columns', function( $columns ) {
$columns['new_column'] = 'New Column';
return $columns;
} );
add_action( 'manage_post_posts_custom_column',
function( $column_name ) {
if ( $column_name == 'new_column' ) {
$terms = get_the_terms( get_the_ID(), 'some-taxonomy' );
if ( $terms ) {
foreach ( $terms as $term ) {
echo esc_html( $term->name );
}
}
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment