我遇到了一个奇怪的问题。
我创建了一个自定义帖子类型但由于某种原因它没有在管理菜单中显示,当我尝试通过url(edit.php?post_type = study_class)访问该页面时,它说“你没有权限访问它页“
这是代码
add_action('init', 'cptui_register_my_cpt_study_class');
function cptui_register_my_cpt_study_class() {
register_post_type('study_class', array(
'label' => 'Study Class',
'description' => '',
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'capability_type' => 'study_class',
'capabilities' => array(
'edit_post' => 'edit_study_class',
'read_post' => 'read_study_class' ,
'delete_post' => 'delete_study_class',
'edit_posts' => 'edit_study_class' ,
'edit_others_posts' => 'edit_others_study_class',
'publish_posts' => 'publish_study_class' ,
'read_private_posts' => 'read_private_study_class',
'read' => 'read',
'delete_posts' => 'delete_study_class',
'delete_private_posts' => 'delete_private_study_class',
'delete_published_posts' => 'delete_published_study_class',
'delete_others_posts' => 'delete_others_study_class',
'edit_private_posts' => 'edit_private_study_class',
'edit_published_posts' => 'edit_published_study_class',
),
'map_meta_cap' => true,
'hierarchical' => false,
'rewrite' => array('slug' => 'study_class', 'with_front' => true),
'query_var' => true,
'supports' => array('title','editor','excerpt','trackbacks','custom-fields','comments','revisions','thumbnail','author','page-attributes','post-formats'),
'labels' => array (
'name' => 'Study Class',
'singular_name' => 'Study Class',
'menu_name' => 'Study Class',
'add_new' => 'Add New Study Class',
'add_new_item' => 'Add new Study Class',
'edit' => 'Edit',
'edit_item' => 'Edit Study Class',
'new_item' => 'New Study Class',
'view' => 'View Study Class',
'view_item' => 'View Study Class',
'search_items' => 'Search Study Class',
'not_found' => ' Study Class not found',
'not_found_in_trash' => ' Study Class not found in Trash',
'parent' => 'Parent Study Class',
)
) );
非常感谢任何帮助。提前谢谢。
答案 0 :(得分:2)
您需要删除capabilities
,capability_type
和map_meta_cap
才能切换回默认的Wordpress帖子功能。
您所做的是首先设置名为study_class
的自定义功能类型 - 该功能未定义。 Wordpress首先使用capability_type
来构建功能对象,然后使用capabilities
参数设置的功能覆盖。来自wordpress codex:
' capability_type'参数用作构造的基础 功能,除非他们明确设置了'功能' 参数。
然后您发送了一系列与相同自定义功能类型相关的功能 - 这是一种重复。作为扩展,功能名称是错误的,因为Wordpress在某些情况下正在寻找plurials:
[cap] => stdClass Object
(
// Meta capabilities
[edit_post] => "edit_{$capability_type}"
[read_post] => "read_{$capability_type}"
[delete_post] => "delete_{$capability_type}"
// Primitive capabilities used outside of map_meta_cap():
[edit_posts] => "edit_{$capability_type}s"
[edit_others_posts] => "edit_others_{$capability_type}s"
[publish_posts] => "publish_{$capability_type}s"
[read_private_posts] => "read_private_{$capability_type}s"
// Primitive capabilities used within map_meta_cap():
[read] => "read",
[delete_posts] => "delete_{$capability_type}s"
[delete_private_posts] => "delete_private_{$capability_type}s"
[delete_published_posts] => "delete_published_{$capability_type}s"
[delete_others_posts] => "delete_others_{$capability_type}s"
[edit_private_posts] => "edit_private_{$capability_type}s"
[edit_published_posts] => "edit_published_{$capability_type}s"
[create_posts] => "edit_{$capability_type}s"
)
要使这项工作正常,您需要先create this capability type。
答案 1 :(得分:0)
功能上的问题,您没有这样的功能,因此您无法查看或编辑帖子类型。 尝试删除功能和capability_type。