0

私は、その人が5つ以上の投稿を投稿しようとし、特定の役割(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 に答える