我正在制作wordpress插件。我创建了一个自定义帖子类型并创建了两个用户角色来创建和编辑帖子类型。但问题是,当我想创建自定义帖子类型的新帖子时,它会显示“类别”和“帖子标记”,但复选框,“类别”和“帖子标记”元框内的文本区域将被禁用。
private function _cpCreateCustomPostType(){
$labels = array(
'name' => __( 'Custom Posts' ), //- general name for the post type, usually plural. The same as, and overridden by $post_type_object->label
'singular_name' => __( 'Custom Post' ), //- name for one object of this post type. Defaults to value of name
'menu_name' => __( 'Custom Post Menu Name' ), //- the menu name text. This string is the name to give menu items. Defaults to value of name
'all_items' => __( 'Custom Post All Items' ), //- the all items text used in the menu. Default is the Name label
'add_new' => __('Add New','Custom Post'), //- the add new text. The default is Add New for both hierarchical and non-hierarchical types. When internationalizing this string, please use a gettext context matching your post type. Example: _x('Add New', 'product');
'add_new_item' => __( 'Add New Post/Add New Page (Custom Post)' ), //- the add new item text. Default is Add New Post/Add New Page
'edit_item' => __( 'Edit Post/Edit Page (Custom Post)' ), //- the edit item text. Default is Edit Post/Edit Page
'new_item' => __( 'New Post/New Page (Custom Post)' ), //- the new item text. Default is New Post/New Page
'view_item' => __( 'View Post/View Page (Custom Post)' ), //- the view item text. Default is View Post/View Page
'search_items' => __( 'Search Posts/Search Pages (Custom Post)' ), //- the search items text. Default is Search Posts/Search Pages
'not_found' => __( 'No posts found/No pages found (Custom Post)' ), //- the not found text. Default is No posts found/No pages found
'not_found_in_trash' => __( 'No posts found in Trash/No pages found in Trash (Custom Post)' ), //- the not found in trash text. Default is No posts found in Trash/No pages found in Trash
'parent_item_colon' => __( 'Parent Page (Custom Post)' ) //- the parent text. This string isn't used on non-hierarchical types. In hierarchical ones the default is Parent Page
);
$args = array(
'labels' => $labels,
'public' => true,
'menu_position' => 15,
'capability_type' => 'custom_post',
'map_meta_cap' => true,
'supports' => array( 'title', 'editor', 'comments' ),
'taxonomies' => array( 'category', 'post_tag' ),
'has_archive' => false
);
if(!post_type_exists('custom_post')){
register_post_type('custom_post',$args);
}
register_taxonomy_for_object_type('category', 'custom_post');
register_taxonomy_for_object_type('post_tag', 'custom_post');
}
private function _cpAddRoles() {
add_role('cp_author', 'Custom Post Author', array(
'edit_custom_posts' => true,
'read' => true, // True allows that capability
));
add_role('cp_editor', 'Custom Post Editor', array(
'edit_custom_posts' => true,
'read' => true, // True allows that capability
));
}
答案 0 :(得分:0)
我已经更改了您的代码。请使用此代码..
add_action('init','create_custom_posttype');
function create_custom_posttype(){
$labels = array(
'name' => __( 'Custom Posts' ), //- general name for the post type, usually plural. The same as, and overridden by $post_type_object->label
'singular_name' => __( 'Custom Post' ), //- name for one object of this post type. Defaults to value of name
'menu_name' => __( 'Custom Post Menu Name' ), //- the menu name text. This string is the name to give menu items. Defaults to value of name
'all_items' => __( 'Custom Post All Items' ), //- the all items text used in the menu. Default is the Name label
'add_new' => __('Add New','Custom Post'), //- the add new text. The default is Add New for both hierarchical and non-hierarchical types. When internationalizing this string, please use a gettext context matching your post type. Example: _x('Add New', 'product');
'add_new_item' => __( 'Add New Post/Add New Page (Custom Post)' ), //- the add new item text. Default is Add New Post/Add New Page
'edit_item' => __( 'Edit Post/Edit Page (Custom Post)' ), //- the edit item text. Default is Edit Post/Edit Page
'new_item' => __( 'New Post/New Page (Custom Post)' ), //- the new item text. Default is New Post/New Page
'view_item' => __( 'View Post/View Page (Custom Post)' ), //- the view item text. Default is View Post/View Page
'search_items' => __( 'Search Posts/Search Pages (Custom Post)' ), //- the search items text. Default is Search Posts/Search Pages
'not_found' => __( 'No posts found/No pages found (Custom Post)' ), //- the not found text. Default is No posts found/No pages found
'not_found_in_trash' => __( 'No posts found in Trash/No pages found in Trash (Custom Post)' ), //- the not found in trash text. Default is No posts found in Trash/No pages found in Trash
'parent_item_colon' => __( 'Parent Page (Custom Post)' ) //- the parent text. This string isn't used on non-hierarchical types. In hierarchical ones the default is Parent Page
);
$args = array(
'labels' => $labels,
'public' => true,
'menu_position' => 15,
'map_meta_cap' => true,
'supports' => array( 'title', 'editor', 'comments' ),
'taxonomies' => array( 'category', 'post_tag' ),
'has_archive' => false
);
if(!post_type_exists('custom_post')){
register_post_type('custom_post',$args);
}
}
删除'capability_type'=>代码中的'custom_post'..