我正在从头开始构建一个wordpress主题。我有一些经验,但我对我的定制非常细致,所以我在这一点上遇到了一些问题。
问题如下:我创建了一些特殊的帖子类型,它们有自己的功能,并允许一些自定义的新角色访问它们。一切正常但是当这个新角色 - “写作者” - 在后端写道时,我创建的不同帖子类型的帖子在帖子类型仪表板中混淆了,就在它列出帖子的位置。
所以我们有这些帖子类型: - 评论 - 预览
评论信息中心列出了该作者撰写的评论和预览帖子,预览仪表板也是如此。
这不会发生在管理员身上。这就是让我认为这是一种许可的原因。
这是帖子类型代码:
// ==================================== //
// R E V I E W S //
// ==================================== //
// Register Custom Post Type
function custom_post_type_reviews() {
$labels = array(
'name' => _x( 'Reviews', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Review', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Reviews', 'text_domain' ),
'name_admin_bar' => __( 'Reviews', 'text_domain' ),
'archives' => __( 'Reviews archive', 'text_domain' ),
'parent_item_colon' => __( 'Parent Item:', 'text_domain' ),
'all_items' => __( 'All the reviews', 'text_domain' ),
'add_new_item' => __( 'Add new review', 'text_domain' ),
'add_new' => __( 'Add new', 'text_domain' ),
'new_item' => __( 'Add item', 'text_domain' ),
'edit_item' => __( 'Edit item', 'text_domain' ),
'update_item' => __( 'Update item', 'text_domain' ),
'view_item' => __( 'View item', 'text_domain' ),
'search_items' => __( 'Search Item', 'text_domain' ),
'not_found' => __( 'Not found', 'text_domain' ),
'not_found_in_trash' => __( 'Not found in trash', 'text_domain' ),
'featured_image' => __( 'Featured image', 'text_domain' ),
'set_featured_image' => __( 'Add featured image', 'text_domain' ),
'remove_featured_image' => __( 'Remove featured image', 'text_domain' ),
'use_featured_image' => __( 'Use featured image', 'text_domain' ),
'insert_into_item' => __( 'insert into item', 'text_domain' ),
'uploaded_to_this_item' => __( 'Update to this item', 'text_domain' ),
'items_list' => __( 'Items lists', 'text_domain' ),
'items_list_navigation' => __( 'Items list navigation', 'text_domain' ),
'filter_items_list' => __( 'Filter items list', 'text_domain' ),
);
$capabilities = array(
'publish_posts' => 'publish_reviews',
'edit_posts' => 'edit_reviews',
'edit_others_posts' => 'edit_others_reviews',
'delete_posts' => 'delete_reviews',
'delete_others_posts' => 'delete_others_reviews',
'read_private_posts' => 'read_private_reviews',
'edit_post' => 'edit_review',
'delete_post' => 'delete_review',
'read_post' => 'read_review',
);
$args = array(
'label' => __( 'Reviews', 'text_domain' ),
'description' => __( 'Reviews', 'text_domain' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'author','comments' ),
'taxonomies' => array( 'categories', 'post_tag', ),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-media-text',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'map_meta_cap' => true,
'capability_type' => 'review',
'capabilities' => $capabilities,
);
register_post_type( 'reviews', $args );
}
add_action( 'init', 'custom_post_type_reviews', 0 );
为了创建角色,我安装了一个名为Memebers的插件,我附加了一个分配给我创建的“角色”的功能的图像。 Role capabilities
我不知道这可能是什么,但我不是一个新闻专业人士。
感谢!!!
答案 0 :(得分:0)
我在map_meta_cap
,capability_type
和capabilities
的组合中看到了各种潜在错误。请查看the Codex中的所有错误。我认为它应该适用于以下情况:
<强>(1)强>
capability_type
设为review
map_meta_cap
设置为false
capabilities
角色功能中的角色应该是插件和单数匹配the Codex - 我的意思是“评论”或“评论”。
<强>(2)强>
capability_type
设为review
map_meta_cap
设置为true
capabilities
- 查看Codex 检查$capabilites
内的数组是否与角色编辑器中使用的$capabilities
匹配。
答案 1 :(得分:0)
我找到了混合帖子的内容。正是这个函数我用来列出作者的帖子,即使是作者页面中的自定义帖子。
function custom_post_author_archive( &$query )
{
if ( $query->is_author )
$query->set( 'post_type', all_post_types() );
remove_action( 'pre_get_posts', 'custom_post_author_archive' );
}
add_action( 'pre_get_posts', 'custom_post_author_archive' );