admin管理员组文章数量:1292172
I created 4 custom post types.
Each author can write 1 post in each custom post type.
When an author wrote 1 post in a custom post type, I would like to remove "Add new.. (CPT)" for the custom post type concerned in admin menu.
For the moment, the limitation of 1 post works fine but I can't delete "Add new...(CPT)" in the admin menu.
Can I have some help please ?
$post_types_name = array('subject-imposed', 'subject-free', 'dissertation', 'curriculum-vitae');
foreach ($post_types_name as $post_type_name) {
$count_post = count_user_posts(get_current_user_id(), $post_type_name, true);
$max_posts = 1; //the number of max published posts
if ($count_post >= $max_posts) {
add_action( 'admin_menu', function() use ( $post_type_name ) {
remove_submenu_page( 'edit.php?post_type='.$post_type_name, 'post-new.php?post_type='.$post_type_name );
}
);
}
}
UPDATE :
Based on this hook
function remove_submenu() {
remove_submenu_page( 'edit.php?post_type=posttype', 'post-new.php?post_type=posttype' );
}
add_action( 'admin_menu', 'remove_submenu', 999 );
本文标签: Limit to one post for each custom post type
版权声明:本文标题:Limit to one post for each custom post type 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741532879a2383859.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论