Only display comments from registered users (WordPress)
Posted March 1st 2014, 7:10pm
Hi there,

I got a question, I'm working on a system where it bridge up with phpBB and everything is working just fine, well almost.

I got a nasty bug that I can't fix (and it may never be) and I have discovered that it caused by people who got a user_id of 0 in the wp_comments table.

The way that I was going to work around this is to add AND >= '1' to the sql statement that produce the comments.

My problem is, I'm not sure how I can go about hooking into it without having to hack the core.

Does anyone have any ideas on how I can add the extra sql needed?

Thank-you :)
φ
Posts: 115
Joined: May 26th 2013, 12:17am
Likes Given: 60
Likes Received: 7
Only display comments from registered users (WordPress)
Posted March 1st 2014, 9:51pm
Generate the query yourself:

$comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1' AND user_id <> 0 ORDER BY comment_date", $post->ID))

This will generate a $comments object for a single post containing only comments from registered users.
φ
Posts: 1599
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 357

Who is online

Users browsing this forum: No registered users and 0 guests