WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

is there a nice function I can use to limit logged in users to one comment per post? I'm setting up a review system and only one review permitted per user. Thanks.

share|improve this question
No, there is no such nice function. You have to develop it by yourself. – Eugene Manuilov Feb 7 '13 at 17:46
@EugeneManuilov - that is what this site is here for! :-) – AndrettiMilas Feb 7 '13 at 17:52
up vote 1 down vote accepted
global $current_user;
$args = array(
    'user_id' => $current_user->ID,
    'post_id' = 100, // post ID. Can be '$post->ID' depending where you are calling this from
    'count' => true
if(get_comments($args) >= 1){
    echo 'disabled';
} else {


Based on AndrettiMilas code.

share|improve this answer
How would I code the '$post->ID' bit? There are many posts so don't think I can use 'post_id' = 100 - I am calling this from comments.php thanks. – user1684099 Feb 8 '13 at 10:33
'post_id' = $post->ID, – Max Yudin Feb 8 '13 at 10:38
Thanks! I really need to brush up on this stuff. – user1684099 Feb 8 '13 at 10:47
btw sorry AndrettiMilas for not crediting but I did already find this code and was the last bit I needed. – user1684099 Feb 8 '13 at 10:49

See if this still works:

global $current_user;
$args = array('user_id' => $current_user->ID);
$usercomment = get_comments($args);
if(count($usercomment) >= 1){
    echo 'disabled';
} else {

My source

share|improve this answer
You can use 'count' => true argument to eliminate count() call. If set to true, get_comments() will return comments count only. – Max Yudin Feb 7 '13 at 21:22
Thanks AndrettiMilas but this function works only looking at all posts - I need to modify it to only look at the current post? Thanks. – user1684099 Feb 8 '13 at 9:18

Your Answer


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.