Sub*_*kar 3 wordpress custom-post-type custom-taxonomy
我创建了一个名为的自定义帖子类型user-story。该$args如下所示:
$args = array(
'labels' => $labels,
'hierarchical' => true,
'description' => 'description',
'taxonomies' => array('category', 'story-type', 'genre'),
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'http://webmaster.webmastersuccess.netdna-cdn.com/wp-content/uploads/2015/03/pencil.png',
'public' => true,
'has_archive' => true,
'query_var' => true,
'capability_type' => 'post',
'supports' => $supports,
'rewrite' => $rewrite,
'register_meta_box_cb' => 'add_story_metaboxes' );
register_post_type('user_story', $args);
Run Code Online (Sandbox Code Playgroud)
问题就在这里'taxonomies' => array('category', 'story-type', 'genre'),。我看不到我的分类story-type,并genre在添加新的故事在管理页面。仅category显示。
这两个story-type和genre是自定义分类。我停用了CPT插件(user_story),然后重新激活了它。但是仍然没有超出自定义分类标准。
这两个自定义分类法都是通过插件注册的,它们在“管理”菜单中可见。这些分类法下注册的术语也会显示在各自的列表页面中。
屏幕截图1:分类法中注册的术语列表 story-type
屏幕截图2:分类法中注册的术语列表 genre
屏幕快照3:“添加新故事”页面-除了仅category列出内置分类法以外,没有列出上述其他分类法
我引用了这个。
小智 5
这应该会有所帮助:https : //codex.wordpress.org/Function_Reference/register_taxonomy
将此代码放在您的functions.php文件中,并将自定义分类法添加到自定义帖子类型中。
<?php
add_action( 'init', 'create_user_story_tax' );
function create_user_story_tax() {
/* Create Genre Taxonomy */
$args = array(
'label' => __( 'Genre' ),
'rewrite' => array( 'slug' => 'genre' ),
'hierarchical' => true,
)
register_taxonomy( 'genre', 'user-story', $args );
/* Create Story Type Taxonomy */
$args = array(
'label' => __( 'Story Type' ),
'rewrite' => array( 'slug' => 'story-type' ),
'hierarchical' => true,
)
register_taxonomy( 'story-type', 'user-story', $args );
}
?>
Run Code Online (Sandbox Code Playgroud)