我已经为这个特定的帖子类型创建了一个自定义帖子类型(书籍),然后是自定义分类法(book_cat)。它工作正常但如果我点击仪表板中的所有书籍页面,则没有列显示哪些类别(book_cat)已分配了一本书(如果有的话)。我需要点击每本书进行编辑并查看。
寄存器新的帖子类型功能是:
function post_types() {
register_post_type('book', array(
'supports' => array('title', 'editor', 'excerpt'),
'public' => true,
'labels' => array(
'name' => 'Books',
'add_new_item' => 'Add New Book',
'edit_item' => 'Edit Book',
'all_items' => 'All Books',
'singular_name' => 'Book'
),
'menu_icon' => 'dashicons-align-center',
'taxonomies' => array('book_cat')
));
}
add_action('init', 'post_types');
分类标准是:
function books_init() {
$labels = array(
'name' => _x( 'Books Cat', 'taxonomy general name' ),
'singular_name' => _x( 'Book Cat', 'taxonomy singular name' ),
'search_items' => __( 'Search Book Cat' ),
'popular_items' => __( 'Popular Book Cat' ),
'all_items' => __( 'All Book Cats' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit BCat' ),
'update_item' => __( 'Update BCat' ),
'add_new_item' => __( 'Add New BCat' ),
'new_item_name' => __( 'New BCat Name' ),
'separate_items_with_commas' => __( 'Separate BCats with commas' ),
'add_or_remove_items' => __( 'Add or remove Bcats' ),
'choose_from_most_used' => __( 'Choose from the most used Bcats' ),
'menu_name' => __( 'Book Cats' ),
);
// create a new taxonomy
register_taxonomy(
'book_cat',
'book',
array(
'labels' => $labels,
'rewrite' => array( 'slug' => 'bcat' ),
)
);
}
add_action( 'init', 'books_init' );
答案 0 :(得分:2)
您需要添加show_admin_column,如下所示:
// create a new taxonomy
register_taxonomy(
'book_cat',
'book',
array(
'labels' => $labels,
'rewrite' => array( 'slug' => 'bcat' ),
'show_admin_column' => true,
)
);
}
add_action( 'init', 'books_init' );