Ask any question about WordPress here... and get an instant response.
Post this Question & Answer:
How can I create a custom post type with specific capabilities in WordPress? Pending Review
Asked on Apr 12, 2026
Answer
Creating a custom post type in WordPress allows you to organize and manage different types of content beyond the default posts and pages. You can define specific capabilities for your custom post type to control what users can do with it.
<!-- BEGIN COPY / PASTE -->
function my_custom_post_type() {
$labels = array(
'name' => 'Books',
'singular_name' => 'Book',
'add_new' => 'Add New',
'add_new_item' => 'Add New Book',
'edit_item' => 'Edit Book',
'new_item' => 'New Book',
'all_items' => 'All Books',
'view_item' => 'View Book',
'search_items' => 'Search Books',
'not_found' => 'No books found',
'not_found_in_trash' => 'No books found in Trash',
'menu_name' => 'Books'
);
$args = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'supports' => array('title', 'editor', 'thumbnail'),
'capability_type' => 'book',
'map_meta_cap' => true,
'capabilities' => array(
'publish_posts' => 'publish_books',
'edit_posts' => 'edit_books',
'edit_others_posts' => 'edit_others_books',
'delete_posts' => 'delete_books',
'delete_others_posts' => 'delete_others_books',
'read_private_posts' => 'read_private_books',
'edit_post' => 'edit_book',
'delete_post' => 'delete_book',
'read_post' => 'read_book',
),
);
register_post_type('book', $args);
}
add_action('init', 'my_custom_post_type');
<!-- END COPY / PASTE -->Additional Comment:
- Replace "Books" and "Book" with the name of your custom post type.
- The 'capability_type' and 'capabilities' arrays define custom capabilities for the post type.
- Ensure you assign these capabilities to the appropriate user roles using a role management plugin or custom code.
- Use the 'init' action hook to register your custom post type.
Recommended Links:
