Any ideas on how to make this happen?
It seems easy enough: "If the user has already commented on this post, don't show the comments form."
Or would that require loops and inflict crazy load on the server/database?
It depends I suppose. Do they have to be registered to post a comment? If not there probably isn't an easy straight forward way.
Yes they do! It's a member-only site. We could even log by IP, cookie, etc if we needed to...
I'm guessing this is going to require hacking at the comments.php file in your theme. Looks like it loads and parses all the comments in there in a for-each loop, shouldn't be too hard to keep a check if a comment's been posted by the currently-logged-in user and decide whether or not to show the form.
hmm, cool!
I don't suppose you have in your bookmarks a compendium of all PHP functions that exist inside Wordpress?
Sweet! http://codex.wordpress.org/Function_Reference/count_user_posts -- now if I can get that specific to a single posting... that'd totally negate loops and server strain.
yeah, no need for an extra loop. you could just do something like...
$count = $wpdb->query("SELECT user_id FROM wp_comments WHERE user_id=$current_user->ID AND comment_post_ID=$post_id");
... probably
assuming you are in "the loop" and have the current user logged in, $count will be the number of comments they've made on the current post.
that's just out of my ass though, i haven't tested it or anything.
I think you missed the point of what I was saying.
If you look at the code, you'll see it loops over the existing comments (to render them). All you'd need to do would be to add in a check (in the existing loop) to see if the comment was made by the logged-in user, and then when it comes to rendering the form (or not) just see if the check was true or not. No need for db access or anything beyond a couple of extra if() statements.
Originally posted by: Stickman I think you missed the point of what I was saying.
If you look at the code, you'll see it loops over the existing comments (to render them). All you'd need to do would be to add in a check (in the existing loop) to see if the comment was made by the logged-in user, and then when it comes to rendering the form (or not) just see if the check was true or not. No need for db access or anything beyond a couple of extra if() statements.
Ah yeah, I just glanced over your response and was responding to Xdude looking to get the count. That's much easier, and save a db hit.