Created
November 5, 2011 20:54
Sample Taxonomy Column on edit.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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