Is it possible to limit the number of posts a admin can create in a custom post type? It's for a plugin and the admin should only be able to create 10 posts. Thanks.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Here you go (untested, but you should get the idea):
function check_allowed( $post_id ) {
$current_user = wp_get_current_user();
$q = new WP_Query(array('post_type'=>'limited','post_author'=>$current_user->ID));
if($q->found_posts >=10) {
return false;
}
}
add_action( 'publish_post', 'check_allowed' );
Btw: You probably do not want to limit admins in the number of posts they may publish, use editors or a custom role for this purpose.