我用具有相同设置的register_taxonomy()创建了两个分类法
register_taxonomy(
'books',
'books',
array(
'label' => __( 'Kategorie' ),
'rewrite' => array( 'slug' => 'books' ),
'hierarchical' => true,
'show_admin_column' => true,
'show_ui' => true,
'capabilities' => array(
'manage_terms' => 'manage_books',
'edit_terms' => 'edit_books',
'delete_terms' => 'delete_books',
'assign_terms' => 'assign_books',
)
)
);
register_taxonomy(
'genre',
'genre',
array(
'label' => __( 'Tag' ),
'rewrite' => array( 'slug' => 'genre' ),
'hierarchical' => true,
'show_admin_column' => true,
'show_ui' => true,
'capabilities' => array(
'manage_terms' => 'manage_genre',
'edit_terms' => 'edit_genre',
'delete_terms' => 'delete_genre',
'assign_terms' => 'assign_genre',
)
)
);
如果我想显示书中的术语,那么可以使用,但是如果我想显示体裁分类法,我会得到一个空语句。
$ books = get_the_terms($ id,'books');
=>获取所有标签
$ genre = get_the_terms($ id,'genre');
=>获取没有任何值的NULL
答案 0 :(得分:0)
您需要将默认功能(而不是“ manage_genre”)添加到其他“ manage_categories”中,请检查以下代码
register_taxonomy( 'genre',
'genre',
array(
'label' => __( 'Tag' ),
'rewrite' => array( 'slug' => 'genre' ),
'hierarchical' => true,
'show_admin_column' => true,
'show_ui' => true,
'capabilities' => array(
'manage_terms' => 'manage_categories',
'edit_terms' => 'manage_categories',
'delete_terms' => 'manage_categories',
'assign_terms' => 'edit_posts'
)
)
)