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
}
}
的是應該工作的代碼。什麼不適合你? –
爲什麼在運行查詢之前不檢查'current_user_is('s2member_level1')'? –
@JosephSilber我改變了上面的代碼來反映大於。我是在PHP編程新手。我可以使用這個操作員,還是我需要表達更大的比另一種方式?如果是這樣,怎麼樣? – user1615690