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!
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!
Share Improve this question asked Apr 6, 2020 at 6:31 rrhdevrrhdev 11 bronze badge1 Answer
Reset to default 0This 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();
}