限制每位作者/角色的帖子

时间:2012-08-22 02:00:32

标签: wordpress

我正在尝试创建一个函数,如果该人试图发布超过五个帖子并且也处于特定角色(s2成员1),则会杀死Wordpress。我正在使用自定义帖子类型。

global $current_user; // get the current author
$userid = $current_user->ID;
$args = array(
    'post_type' => 'listing',
    'post_status' => 'publish',
    'author' => $userid
);
$the_posts = get_posts ( $args ); // get the published posts for that author
$post_count = count($the_posts); // count the number of published posts for the author
$N = 5; // set number for max posts per user
if ($post_count > $N) {
    if (current_user_is('s2member_level1')) {   
        wp_die( 'message' ); // if the number of posts is more than N, kill the current post attempt so the author can't post
    }
}

1 个答案:

答案 0 :(得分:0)

非常简单:

$user_post_count = count_user_posts( $user_ID ); // get total post for user
if ($user_post_count > 1) { // define number 

<your code here> // code here

}