为什么我的自定义 post 类型只针对我的自定义用户角色显示?

Why is my custom post type only showing for my custom user role?

我为我的餐厅创建了一个自定义 post 类型。它目前仅针对我的 restaurant_owner 自定义用户角色显示。我希望它也显示给管理员。

我做错了什么?

自定义 Post 类型:

add_action( 'init', 'pt_restaurant');
function pt_restaurant() { 
register_post_type( 'bounty_product', array(
  'labels' => array(
     'name' => 'Restaurants',
     'singular_name' => 'Restaurant',
     'add_new' => 'Add New',
     'add_new_item' => 'Add New Restaurant',
     'edit' => 'Edit',
     'edit_item' => 'Edit Restaurant',
     'new_item' => 'New Restaurant',
     'view' => 'View',
     'view_item' => 'View Restaurant',
     'search_items' => 'Search Restaurants',
     'not_found' => 'No Restaurants found',
     'not_found_in_trash' => 'No Restaurants found in Trash',
     'parent' => 'Parent Restaurant'),
  'description' => 'Used for the Restaurant section',
  'public' => true,
  'capability_type' => array('bounty_product','bounty_products'),
  'map_meta_cap' => true,
  'show_in_menu' => true,
  'menu_position' => 20,
  'has_archive' => true,
  'supports' => array( 'title', 'editor', 'comments', 'thumbnail', 'custom-fields' ),

));

自定义用户角色:

add_action('init', 'restaurant_owner_user_role');
function restaurant_owner_user_role() {
    add_role('restaurant_owner', 'Restaurant Owner',
        array (
                'edit_bounty_product' => true,
                'delete_bounty_product' => false,
                'read_bounty_product' => true,
                'publish_bounty_products' => false,
                'edit_bounty_products' => true,
                'edit_others_bounty_products' => false,
                'delete_bounty_products' => false,
                'delete_others_bounty_products' => false,
                'read_private_bounty_products' => false,            

                'read' => true,
        )
    );
}

您只是为您的自定义用户角色授予权限,这就是为什么管理员无法 edit/update/delete 您的 CPT。尝试在 functions.php

中使用以下代码
function add_theme_caps() {
    // gets the administrator role
    $admins = get_role( 'administrator' );

    $admins->add_cap( 'edit_bounty_product' ); 
    $admins->add_cap( 'delete_bounty_product' ); 
    $admins->add_cap( 'read_bounty_product' ); 
    $admins->add_cap( 'publish_bounty_products' ); 
    $admins->add_cap( 'edit_bounty_products' ); 
    $admins->add_cap( 'edit_others_bounty_products' ); 
    $admins->add_cap( 'delete_bounty_products' ); 
    $admins->add_cap( 'delete_others_bounty_products' ); 
    $admins->add_cap( 'read_private_bounty_products' ); 
    $admins->add_cap( 'delete_gallery' ); 
}
add_action( 'init', 'add_theme_caps');