限制自定义帖子类型帖子的数量 [英] Limit number of custom post type posts

查看:32
本文介绍了限制自定义帖子类型帖子的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以限制管理员可以在自定义帖子类型中创建的帖子数量?这是一个插件,管理员应该只能创建 10 个帖子.谢谢.

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.

推荐答案

给你(未经测试,但你应该明白了):

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.

这篇关于限制自定义帖子类型帖子的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆