I have a custom post type that I'd like to restrict access to certain roles however, I've already added content using the custom post type and now I have to make them restricted. The capability_type was 'post'
'capability_type' => 'post'
Which is fine as the content show up in the backend however, now as soon as I add any capabilities the content disappears from the backend?
I've tried customising the capability type to include plural definitions to construct my own but as soon as I remove or change capability types it's gone!
full code:
add_action( 'init', 'register_cpt_gallery' );
function register_cpt_gallery() {
$labels = array(
'name' => _x( 'Galleries', 'gallery' ),
'singular_name' => _x( 'Gallery', 'gallery' ),
'add_new' => _x( 'Add New', 'gallery' ),
'add_new_item' => _x( 'Add New Gallery', 'gallery' ),
'edit_item' => _x( 'Edit Gallery', 'gallery' ),
'new_item' => _x( 'New Gallery', 'gallery' ),
'view_item' => _x( 'View Gallery', 'gallery' ),
'search_items' => _x( 'Search Galleries', 'gallery' ),
'not_found' => _x( 'No galleries found', 'gallery' ),
'not_found_in_trash' => _x( 'No galleries found in Trash', 'gallery' ),
'parent_item_colon' => _x( 'Parent Gallery:', 'gallery' ),
'menu_name' => _x( 'Galleries', 'gallery' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'description' => 'Image galleries for teachers classes',
'supports' => array( 'title', 'editor', 'author'),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_icon' => get_bloginfo('template_url') . '/images/imagegallery.png',
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'post',
'capabilities' => array(
'edit_post' => 'edit_gallery',
'edit_posts' => 'edit_galleries',
'edit_others_posts' => 'edit_other_galleries',
'publish_posts' => 'publish_galleries',
'read_post' => 'read_gallery',
'read_private_posts' => 'read_private_galleries',
'delete_post' => 'delete_gallery'
)
);
register_post_type( 'gallery', $args );
}
I've also tested this with a completely new custom post type and regardless of the capability type I get the same issue eg even if I remove it and add my custom one:
'capability_type' => array('movie','movies');