How do I “trash” a custom post type post while logged in as Admin
-
22-10-2019 - |
Question
I am using the members plugin and have a custom post type of "listing"
When I navigate to listings in the backend, I can edit. quickedit, and view. There is no option to trash. I am logged in as the admin.
add_action('init', 'listing_init');
function listing_init()
{
$labels = array(
'name' => _x('Listing', 'post type general name'),
'singular_name' => _x('Listing', 'post type singular name'),
'add_new' => _x('Add New', 'Listing'),
'add_new_item' => __('Add New Listing'),
'edit_item' => __('Edit Listing'),
'new_item' => __('New Listing'),
'view_item' => __('View Listing'),
'search_items' => __('Search Listing'),
'not_found' => __('No Listing found'),
'not_found_in_trash' => __('No Listing found in Trash'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_ui_menu' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'listing',
'map_meta_cap' => true,
'hierarchical' => false,
'menu_position' => 5,
'supports' => array('title','editor','thumbnail'),
'taxonomies' => array('category')
);
register_post_type('listing',$args);
}
this is the functions.php custom post type code that I am using. Everything else works great.
Inside the members plugin I have roles for delete_listing and delete_listings (which I think is not necessary)
Any ideas on what I am doing wrong here?
Solution
Might you need one of these Admin capabilities?
- delete_others_pages
- delete_others_posts
- delete_pages
- delete_plugins
- delete_posts
- delete_private_pages
- delete_private_posts
- delete_published_pages
- delete_published_posts
Unless you've modified the default capabilities for Administrator, to remove one or more of these capabilities, you should be able to delete any Post (of any Post-Type) as an Admin user.
OTHER TIPS
I wrote a tutorial on how to properly apply capabilities with the Members plugin for CPTs.
The gist is to make sure you have all of the proper caps, not just the delete_ cap.