最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to limit specific user ID to 5 comments per post?

programmeradmin3浏览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!

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 badge
Add a comment  | 

1 Answer 1

Reset to default 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();
}
发布评论

评论列表(0)

  1. 暂无评论