Use the map_meta_cap
filter to conditionally prevent users who cannot manage_options
(i.e. administrators) from editing/deleting certain posts:
function wpse_188368_map_meta_cap( $caps, $cap, $user_ID, $args ) {
if ( in_array( $cap, array( 'delete_post', 'edit_post' ) ) && $args && ! current_user_can( 'manage_options' ) /** Only proceed for non-administrators */ ) {
$post_id = $args[0];
if ( in_array( $post_id, array( 1, 2, 3 /* ID's of locked posts */ ) ) )
$caps[] = 'not_allowed'; // Add a required capability they won't have - current_user_can() will then subsequently return false
}
return $caps;
}
add_filter( 'map_meta_cap', 'wpse_188368_map_meta_cap', 10, 4 );
Related Posts:
- Correct Post Count ( All | Published | Drafts | Pending | Trash ) for Custom Post Type when restricting to view own posts
- Show/hide posts and categories based on user meta
- WordPress Front-End user restricted taxonomies
- Multiple domains, Single database, 1 Parent/Master with all content, other domains/slaves with filtered content (based on “location” variable)
- How to Debug the ‘save_post’ Action?
- set_post_thumbnail_size in percent, not pixels?
- Breadcrumbs with Custom Post Types?
- How to query for posts (in hierarchical custom post type) that have children?
- 404 error PageNavi custom type taxonomy | wordpress
- Running a function on post content and CPT meta
- Get the post_type of current taxonomy or category page
- get_the_post_thumbnail() returning empty string on custom post type
- Query for posts in 2 taxonomies
- How do I create an archive page for standard posts?
- custom taxonomy archive by year
- Add management screens to post type
- How to add the post ID (or any other post data) to a Contact Form 7 mail?
- Metabox Populated with a Custom Post Type – How to Output CPT based on Select?
- Can custom taxonomies items have attached properties?
- WordPress if in term*
- Associate custom post types with normal posts
- Combining sorted and random CPT
- how to delete all users and posts based on ‘user_meta’?
- Regex with a possible hyphen
- Expose a custom field of a custom post type to the REST API
- Default text in a specific post type, but not visible?
- Woocommerce custom field search in custom post type [closed]
- Custom rewrite to fetch feed data
- Create custom post with meta field with AJAX and the WordPress REST API
- Change “empty trash” button text?
- Front end access to a SQL data repository – recommended way?
- Adding guestbook to my wordpress site
- Custom Post Type – Support “author” only for admins
- find custom post type post by searching its custom field with my string
- wordpress lists similar type of posts in a custom post type
- FacetWP paging custom wp_query
- Custom Post Type Template Hierarchy – Single post template
- How do I find a way to create a global single.php for a custom post type?
- Display Date & Author Info on Custom Post Type Archive Page
- Rewrite permalink for multiple post types (CPT) with taxonomy term
- Slider from custom post type
- Custom Post Type View Button in Admin Gives 400 Error
- orderby parameter not working in custom query
- Save custom post type not working
- Extra richtext admin textfield for custom posttype with toolbar tabs?
- either single-{custom}.php 404’s OR /taxonomy/ 404’s – custom post type and taxonomy permalinks
- Custom loop request based on custom field
- Content in WP Editor displayed below CPT shortcode [duplicate]
- How do I list the next 7 days and any events (cpt) contained in those days
- Custom Post Types Not Showing Up In query_posts Result
- Do I need a loop to display an object that attached to posts?
- Remove filter and view options from custom post type edit screen
- How to get next post link of child custom post type from parent post and get next post link of parent post from the last child post?
- Using publish_{custom-post-type} hook for custom post type to update meta doesn’t work
- Select custom post type do display from page editor
- update custom taxonomy custom fields
- Filter taxonomy by CPT
- Get Custom Post types data from the API
- CPTs relationship
- Search only one custom post type
- If ACF Post Object post has custom taxonomy term…
- How to group custom posts in admin menu based off taxonomy/postmeta
- publish_post action callback not executed, why?
- minimize wp_query call to database
- How to filter taxonomy of a custom post type and display it in the single post type page in the back end?
- Parent and child categories with their id in drop_down in CPT
- Some permalinks on Apache/localhost development setup return 404’s when set to anything other than plain permalinks
- sorting in wp query based on custom field value
- WooCommerce breadcrumb display custom posts instead of product data
- Include images from pages in wp search.php results in default wp search
- Custom post type post_type_link gives “page not found” on any other custom post type
- Taxonomy’s title
- Display all posts from single taxonomy term
- Enable shortcodes on custom post type
- Custom Post Type shows pagination (w/404) or posts_per_page query, but not both
- custom post type plugin – single template
- getting a blank login page :( any way I can fix this without having to do a clean install?
- Add a image to a post published on a CPT from the front-end
- Pulling in Related Posts based on Post Type array
- Page to show custom posts and one category
- Custom Search not working
- Custom post type post taxonomies
- Custom Template Taxonomy
- How to make nested custom post type slugs work
- pre_get_posts action doesn’t work
- Checking 2 dates against todays date
- WP Build-In Post selector for CPT
- Pagination not working with custom loop
- Bulk remove category from custom post type?
- How to relate one custom post type to another custom post type
- Hide custom post type and use its slug in new plugin menu
- Page template anomaly
- Structure of custom post type / taxonomy?
- Issue On Listing Woocommerce Parent Tag List
- Can WordPress show posts based on a button that the user clicked 2 pages back?
- Creating post custom field text area
- How Do I Add a Custom Post Type URL to Content?
- What is the best way to relate different custom post types?
- Custom Sort Order for Custom Post Type Taxonomy
- Load posts via AJAX without draft status