Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How can i disable the comment form, if the user is already submitted a comment for the specified post?

I am using this now, but this is only good for 1 post / user / website.

<?php
global $current_user;
$args = array('user_id' => $current_user->ID);
$usercomment = get_comments($args);
if(count($usercomment) >= 1){
    echo 'disabled';
} else {
    comment_form();
}
?>
share|improve this question

1 Answer 1

up vote 4 down vote accepted

Simply add the post_id parameter to the get_comments arguments array something like:

global $current_user,$post;
$args = array('user_id' => $current_user->ID,'post_id' => $post->ID);
$usercomment = get_comments($args);
if(count($usercomment) >= 1){
    echo 'disabled';
} else {
    comment_form();
}
share|improve this answer
    
Thanks, works great. –  passatgt Aug 27 '11 at 23:21
    
What about limiting a register user to one comment per post and also 10 comments per entire website? Thanks –  Nicusor Dumbrava Mar 3 '12 at 20:55
    
Ask that as a question –  Bainternet Mar 4 '12 at 5:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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