0

Can someone please give me a function to limit a specific User ID to 5 comments per post? I found several questions on how to put a limit of one comment per post on all users. However, I need to place the limit on only a single User ID. When I tried to modify the code to specify a single user ID it instead applied the limit to all users based on that one ID.

I found a plugin Limit Comments and Word Count that includes an option to place a limit on a specific User ID but for some reason that plugin doesn't work on my site. When I place the limit then no comments will go through for that User ID. It just gives a blank screen after hitting the comment button.

Anyway, if someone can give me a simple function to limit the number of comments per post from a specific User ID I would very much appreciate it. Thanks!

0

This is a simple approach to check whether a user has commented on the post, or not. If they have commented on the post, then disable comment form.

global $current_user;
$args = array('user_id' => $current_user->ID);
$usercomment = get_comments($args);
if(count($usercomment) >= 1){
    echo 'Comment form disabled';
} else {
    comment_form();
}
| improve this answer | |
  • Thanks! That would impose the limit on all users correct? Is there a way to modify the code so that the limit only applies to a single user? For instance, if I only want to limit comments for User ID 810 but no other User ID. That is what I need to do. – rrhdev Apr 6 at 11:38
  • @rrhdev... Yes, you can modify the code for the single user. if you need like that so you check with below codes: global $current_user; $get_current_user = $current_user->ID; if($get_current_user == '810'){ $args = array('user_id' => $get_current_user); $usercomment = get_comments($args); if(count($usercomment) >= 1){ echo 'Comment form disabled'; } else { comment_form(); } } Please check and let us know. Thanks – Sanjay Gupta Apr 6 at 12:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.