Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // reset the column fields and order of the post list table
- add_filter('manage_edit-post_columns', 'manage_edit_post_columns');
- function manage_edit_post_columns($columns) {
- unset($columns['tags']); // optional, removes the "Tags" column
- // add a custom column with a label of "My Custom Taxonomy Column" and slug of my_custom_taxonomy
- $columns['my_custom_taxonomy'] = __('My Custom Taxonomy Column');
- return $columns;
- }
- // tell WordPress what to display in the post list table column we created using the 'manage_edit-post_columns' hook
- add_action( 'manage_posts_custom_column', 'manage_edit_post_column', 10, 2);
- function manage_edit_post_column($column_name, $post_id ) {
- $post = get_post($post_id);
- switch ($column_name) {
- case 'my_custom_taxonomy':
- unset($medgadget_display_term_links);
- $my_custom_taxonomy_terms = get_the_terms( $post_id, 'my_custom_taxonomy_slug' );
- if ( !empty($my_custom_taxonomy_terms) ) {
- $out = array();
- foreach ($my_custom_taxonomy_terms as $term) {
- $out[] = sprintf( '<a href="%s">%s</a>',
- esc_url( add_query_arg( array( 'post_type' => $post->post_type, 'my_custom_taxonomy_slug' => $term->slug ), 'edit.php' ) ),
- esc_html( sanitize_term_field( 'name', $term->name, $term->term_id, 'my_custom_taxonomy_slug', 'display' ) )
- );
- }
- echo join( '<br />', $out );
- }
- else {
- echo 'No terms found';
- }
- break;
- case 'another_custom_column' :
- // example of how to add multiple custom columns, so let's not display anything right now
- break;
- default:
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement