0

我正在尝试创建一个函数,如果该人尝试发布超过五个帖子并且还处于特定角色(s2member 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
    }
}
4

1 回答 1

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

}
于 2013-06-19T21:10:02.823 回答