wordpress - WordPress - 自定义分类法未显示在外观 > 菜单中
问题描述
我有一个名为Resources的自定义帖子类型:
register_post_type(
'resources',
build_post_args(
'resources', 'Resource', 'Resources',
array(
'menu_icon' => 'dashicons-welcome-write-blog',
'menu_position' => 20,
'has_archive' => true,
'public' => true,
'supports' => array('editor', 'title','author','thumbnail', 'revisions'),
'taxonomies' => array('sector', 'subject', 'type'),
)
)
);
我还创建了type
分配给资源的分类法:
register_taxonomy(
'type',
'type',
array(
'hierarchical' => true,
'label' => 'Type',
'query_var' => true,
'rewrite' => array(
'slug' => 'type',
'with_front' => false
)
)
);
在 WordPress 后端,这里是我所有type
的:
但是,当我转到外观 > 菜单 > 并单击类别下拉菜单时,仅显示以下选项:
为什么是这样?
解决方案
resources
您好请添加以下代码并检查您在创建帖子类型时缺少很多东西。(注意:请删除您为创建resources
帖子和type
分类添加的所有代码)
function ro_resources_custom_post_type() {
$labels = array(
'name' => __( 'Resources' ),
'singular_name' => __( 'Resource'),
'menu_name' => __( 'Resources'),
'parent_item_colon' => __( 'Parent Resource'),
'all_items' => __( 'All Resources'),
'view_item' => __( 'View Resource'),
'add_new_item' => __( 'Add New Resource'),
'add_new' => __( 'Add New'),
'edit_item' => __( 'Edit Resource'),
'update_item' => __( 'Update Resource'),
'search_items' => __( 'Search Resource'),
'not_found' => __( 'Not Found'),
'not_found_in_trash' => __( 'Not found in Trash')
);
$args = array(
'label' => __( 'resources'),
'description' => __( 'Best Resources'),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'revisions', 'custom-fields'),
'public' => true,
'hierarchical' => false,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'has_archive' => true,
'can_export' => true,
'exclude_from_search' => false,
'yarpp_support' => true,
'publicly_queryable' => true,
'capability_type' => 'page'
);
register_post_type( 'resources', $args );
}
add_action( 'init', 'ro_resources_custom_post_type', 0 );
add_action( 'init', 'ro_create_resources_custom_taxonomy', 0 );
//create a custom taxonomy name it "type" for your posts
function ro_create_resources_custom_taxonomy() {
$labels = array(
'name' => _x( 'Types', 'taxonomy general name' ),
'singular_name' => _x( 'Type', 'taxonomy singular name' ),
'search_items' => __( 'Search Types' ),
'all_items' => __( 'All Types' ),
'parent_item' => __( 'Parent Type' ),
'parent_item_colon' => __( 'Parent Type:' ),
'edit_item' => __( 'Edit Type' ),
'update_item' => __( 'Update Type' ),
'add_new_item' => __( 'Add New Type' ),
'new_item_name' => __( 'New Type Name' ),
'menu_name' => __( 'Types' ),
);
register_taxonomy('types',array('resources'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'type' ),
));
}
经过测试并且运行良好
推荐阅读
- browser - 渲染非常大的 HTML 文件,例如观看视频
- swift - 我无法在收藏视图中导入照片
- google-apps-script - 在使用 Apps 脚本在 Google 表格中进行 API 调用后,在检测数据变化时标记单元格
- graphql - 如何使用缓存优先/缓存和网络在缓存失效后重新获取 apollo watchQuery
- r - R中的编织问题
- java - 收到错误“Grader.java: Line 10: class expected”但不确定问题出在哪里,我已经经历过多次但无法分辨
- lambda - 如果已经给出括号,则 lambda 演算中括号的顺序?
- react-native - 无效的挂钩调用。钩子只能在函数组件的主体内部调用。在反应原生签名画布中
- node.js - 在 Nodejs 中等待函数完成
- html - 我的下拉导航栏不起作用