Ask any question about WordPress here... and get an instant response.
Post this Question & Answer:
How do I create a custom post type with specific capabilities in WordPress?
Asked on Apr 03, 2026
Answer
Creating a custom post type in WordPress allows you to organize and display different types of content beyond the default posts and pages. You can define specific capabilities for this custom post type to control user permissions.
<!-- BEGIN COPY / PASTE -->
function my_custom_post_type() {
$labels = array(
'name' => 'Books',
'singular_name' => 'Book',
'menu_name' => 'Books',
'name_admin_bar' => 'Book',
'add_new' => 'Add New',
'add_new_item' => 'Add New Book',
'new_item' => 'New Book',
'edit_item' => 'Edit Book',
'view_item' => 'View Book',
'all_items' => 'All Books',
'search_items' => 'Search Books',
'not_found' => 'No books found.',
'not_found_in_trash' => 'No books found in Trash.'
);
$args = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'books'),
'capability_type' => 'book',
'capabilities' => array(
'edit_post' => 'edit_book',
'read_post' => 'read_book',
'delete_post' => 'delete_book',
'edit_posts' => 'edit_books',
'edit_others_posts' => 'edit_others_books',
'publish_posts' => 'publish_books',
'read_private_posts' => 'read_private_books',
),
'map_meta_cap' => true,
'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments')
);
register_post_type('book', $args);
}
add_action('init', 'my_custom_post_type');
<!-- END COPY / PASTE -->Additional Comment:
- Use the "register_post_type" function within an "init" action hook to ensure it runs at the correct time.
- Define custom capabilities to control access to the custom post type, allowing for granular permission settings.
- Remember to flush rewrite rules after registering a new post type by visiting the "Settings → Permalinks" page.
- Consider using a plugin like "Members" to manage roles and capabilities more easily.
Recommended Links:
