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
}
}
입니다 작동합니다 같은 코드입니다. 너를 위해 일하지 않는게 뭐야? –
쿼리를 실행하기 전에'current_user_is ('s2member_level1')'을 (를) 확인하지 않는 이유는 무엇입니까? –
@JosephSilber 위 코드를 변경하여보다 큼을 나타냅니다. 나는 PHP 프로그래밍에 새로운 사람이다. 이 연산자를 사용할 수 있습니까? 아니면 다른 방식으로 표현할 필요가 있습니까? 그렇다면 어떻게? – user1615690