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.

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

2 Answers 2

up vote 1 down vote accepted
<?php
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 {
    comment_form();
}

Function_Reference/get_comments

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:

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

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

 
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.