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