I am using the code below to count the number of comments by a certain user:
global $wpdb;
$count = $wpdb->get_var(
'SELECT COUNT( comment_id ) FROM '. $wpdb->comments .'
WHERE user_id = '.$user->ID.'
AND comment_approved = "1"
AND comment_type NOT IN ("pingback", "trackback" )'
);
I am in addition, using a comment meta field (‘consider’) which takes 0 or 1 as values. To get its value I use:
get_comment_meta($comment_id, 'consider',true);
How can I merge these two operations so that I get the number of comments submitted by the user and which have the meta value 'consider'
equal to 1
? I am not an SQL user and it seems that I need to use inside my SQL query the table wp_commentmeta
?
Your help is always appreciated.
Your basic question is a pure SQL question.
I cleaned that up a bit to be more readable.
What you are doing with that SQL is pretty close, possibly identical to, what you’d get with ….
You aren’t explicitly excluding trackbacks and pingbacks with that but I am pretty sure that trackbacks and pingbacks will never have an associated user ID, so you are excluding them by that mechanism.
Try this :
Hope it helps!