Could we help you? Please click the banners. We are young and desperately need the money
Do you need to disable specific posts in a WordPress admin post table? Use the following function to do so.
This is the code you need. Add it your functions.php:
function disable_posts_in_table($caps, $cap, $user_id, $args) {
// If this condition is true, do nothing
if ( $cap !== 'edit_post' && $cap !== 'delete_post' ) {
return $caps;
}
// If this condition is true, disable the post
if ( disabling_condition ) {
$caps[] = 'do_not_allow';
}
return $caps;
}
add_filter( 'map_meta_cap', 'disable_posts_in_table', 10, 4 );
Replace the "disabling_condition" located in the function. If the condition is true, the post will be disabled inside the post table.