
[英]How do I fetch a link to a custom taxonomies page for a custom post type. (wordpress)
[英]WordPress: How do I add more than one taxonomies in a custom post post type
我创建了一个名为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);
问题出在'taxonomies' => array('category', 'story-type', 'genre'),
我在管理员的“ 添加新故事”页面中看不到我的分类法story-type
和genre
。 仅显示category
。
story-type
和genre
都是自定义分类法。 我停用了CPT插件( user_story
),然后重新激活了它。 但是仍然没有超出自定义分类标准。
这两个自定义分类法都是通过插件注册的,它们在“管理”菜单中可见。 这些分类法下注册的术语也会显示在各自的列表页面中。
屏幕截图1:以分类story-type
注册的术语列表
屏幕截图2:分类genre
注册的术语列表
屏幕快照3:“添加新故事”页面-除了仅列出内置分类法category
未列出上述其他分类法
我引用了这个 。
这应该会有所帮助: 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 );
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.