For anyone who is interested:
register_post_type( 'book', array(
'labels' => array(
'name' => 'Books',
'singular_name' => 'Book',
'add_new' => 'Add New',
'add_new_item' => 'Add New Book',
'edit_item' => 'Edit book',
'edit' => 'Edit',
'new_item' => 'New Book',
'view_item' => 'View Book',
'search_items' => 'Search Books',
'not_found' => 'No books found',
'not_found_in_trash' => 'No books found in Trash',
'view' => 'View Book'
),
'public' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => true,
'query_var' => true,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'custom-fields', 'comments' ),
'taxonomies' => array('category','post_tag')
)
);
register_taxonomy(
'book_category',
'book',
array(
'hierarchical' => true,
'label' => 'Categori?n',
'public' => true,
'query_var' => true,
'show_tagcloud' => true,
'rewrite' => Array(
'slug' => 'book_category')
)
);
function add_new_columns($defaults) {
$defaults['book_cats'] = __('Categori?n');
return $defaults;
}
function add_column_data( $column_name, $post_id ) {
if( $column_name == 'book_cats' ) {
$_posttype = 'book';
$_taxonomy = 'book_category';
$terms = get_the_terms( $post_id, $_taxonomy );
if ( !empty( $terms ) ) {
$out = array();
foreach ( $terms as $c )
$_taxonomy_title = esc_html(sanitize_term_field('name', $c->name, $c->term_id, 'category', 'display'));
$out[] = "<a href='edit.php?book_category=$_taxonomy_title&post_type=$_posttype'>$_taxonomy_title</a>";
echo join( ', ', $out );
}
else {
_e('Uncategorized');
}
}
}
add_filter( 'manage_book_posts_columns', 'add_new_columns' );
add_action( 'manage_posts_custom_column', 'add_column_data', 10, 2 );