简体   繁体   English

为什么我的Wordpress自定义帖子类型没有显示在管理菜单中

[英]Why is my Wordpress Custom Post type not displaying in the Admin Menu

I have this code working on a development site to create a custom post type. 我在开发站点上使用此代码来创建自定义帖子类型。

When I copy it to the live site functions.php file it stops working? 当我将其复制到实时站点的functions.php文件时,它停止工作了吗? Specifically it doesn't show up in the admin menu on the left of the dashboard. 具体来说,它不会显示在信息中心左侧的管理菜单中。 What am I doing wrong? 我究竟做错了什么?

add_action( 'init', 'register_cpt_manufacturer' );
function register_cpt_manufacturer() {
$labels = array(
'name' => _x( 'Manufacturers', 'manufacturer' ),
'singular_name' => _x( 'Manufacturer', 'manufacturer' ),
'add_new' => _x( 'Add New', 'manufacturer' ),
'add_new_item' => _x( 'Add New Manufacturer', 'manufacturer' ),
'edit_item' => _x( 'Edit Manufacturer', 'manufacturer' ),
'new_item' => _x( 'New Manufacturer', 'manufacturer' ),
'view_item' => _x( 'View Manufacturer', 'manufacturer' ),
'search_items' => _x( 'Search Maufacturers', 'manufacturer' ),
'not_found' => _x( 'No maufacturers found', 'manufacturer' ),
'not_found_in_trash' => _x( 'No maufacturers found in Trash', 'manufacturer' ),
'parent_item_colon' => _x( 'Parent Manufacturer:', 'manufacturer' ),
'menu_name' => _x( 'Maufacturers', 'manufacturer' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'description' => 'Look up table to convert PL Serial to Ad Rotator Group',
'supports' => array( 'title', 'editor', 'custom-fields' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'manufacturer',
'map_meta_cap' => true
);
register_post_type( 'manufacturer', $args );
} 

Try Changing the 尝试更改

'capability_type' => 'manufacturer', to
'capability_type' => 'post',

check https://codex.wordpress.org/Function_Reference/register_post_type for more ifno 检查https://codex.wordpress.org/Function_Reference/register_post_type了解更多ifno

Actually the correct answer is to add the "capabilities" array under capability_type like so: 实际上,正确的答案是在capability_type下添加“ capabilities”数组,如下所示:

'capabilities' => array(
'publish_posts' => 'publish_manufacturers',
'edit_posts' => 'edit_manufacturers',
'edit_others_posts' => 'edit_others_manufacturers',
'delete_posts' => 'delete_manufacturers',
'delete_others_posts' => 'delete_others_manufacturers',
'read_private_posts' => 'read_private_manufacturers',
'edit_post' => 'edit_manufacturer',
'delete_post' => 'delete_manufacturer',
'read_post' => 'read_manufacturer'),

Next you will have to download a user role management plugin like "Members" found in the WordPress plugin repository. 接下来,您将必须下载在WordPress插件存储库中找到的用户角色管理插件,例如“ Members”。 There you will assign these capabilities to the administrator and/or additional user roles. 您将在此处将这些功能分配给管理员和/或其他用户角色。 Only afterwards will it appear in the side menu. 之后,它才会出现在侧面菜单中。

Mapping Meta Capabilities 映射元功能

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM