WordPress帖子类型帖子混合在后端非管理员角色中


Wordpress post types posts mixing in backend non admine roles

我正在从头开始构建一个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的插件,我正在附加分配给我创建的"角色"的功能的图像。角色功能

我不知道这可能是什么,但我不是一个文字新闻专业人士。

谢谢!!!

我在map_meta_capcapability_typecapabilities的组合中看到各种潜在的错误 在法典中查看所有这些错误。我认为它应该适用于以下情况:

(1)

  • capability_type设置为review
  • map_meta_cap设置为false
  • 不需要使用capabilities

您的角色能力中的角色应该与 Codex 匹配插件和单数 - 我的意思是"审查"或"审查"。

(二)

  • capability_type设置为review
  • map_meta_cap设置为true
  • 使用capabilities - 检查法典

检查$capabilites内的数组是否与角色编辑器中使用的$capabilities匹配。

我找到了混合帖子的内容。正是这个功能,我用来列出作者的帖子,即使是作者页面中的自定义帖子。

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' );