One comment per user per post

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();
}
?>

Related posts

Leave a Reply

1 comment

  1. 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();
    }