count number of user comments with a specific comment meta value

Your basic question is a pure SQL question. $count = $wpdb->get_var( ‘SELECT COUNT( comments.comment_ID ) FROM ‘. $wpdb->comments .’ as comments LEFT JOIN ‘.$wpdb->commentmeta.’ AS cmeta ON comments.comment_ID = cmeta.comment_id WHERE user_id = 1 AND comment_approved = “1” AND comment_type NOT IN (“pingback”, “trackback” ) AND cmeta.meta_key = “rating” AND cmeta.meta_value = 5′ ); I … Read more

Add Comment Custom Field

Here you go: Adding Custom Fields to WordPress Comment Forms? And another awesome post on this: http://wpengineer.com/2214/adding-input-fields-to-the-comment-form/ Functions are available to add/update, delete comment meta, similar to post and user meta. Edit: Here’s an example to give you a start (put the code into the functions.php or in a custom plugin): Add the fields to … Read more

Query & Sort Comments by custom comment meta

Unfortunately it’s unsupported by the applicable WordPress functions for querying comments, which is primarily due to(i feel) not enough people(or anyone) yet asking for it. I want to highlight a couple of core files here to help understand the issue. First up comments-template.php, the comment_template function, it’s this function that queries for comments and then … Read more

change the comment time output to: X time ago instead of actual date and time

What you need is: https://codex.wordpress.org/Function_Reference/human_time_diff So this should do exactly what you need: <?php printf( _x( ‘%s ago’, ‘%s = human-readable time difference’, ‘your-text-domain’ ), human_time_diff( get_comment_time( ‘U’ ), current_time( ‘timestamp’ ) ) ); ?>

Is it possible to show custom comment metadata in the admin panel?

To show the content on individual edit pages you need to add custom meta boxes to the comment edit page. You’ll use the key comment for the $page argument of add_meta_box. <?php add_action( ‘add_meta_boxes_comment’, ‘pmg_comment_tut_add_meta_box’ ); function pmg_comment_tut_add_meta_box() { add_meta_box( ‘pmg-comment-title’, __( ‘Comment Title’ ), ‘pmg_comment_tut_meta_box_cb’, ‘comment’, ‘normal’, ‘high’ ); } function pmg_comment_tut_meta_box_cb( $comment ) … Read more

Adding another state (spam, reject, approve) to wordpress comments?

Assuming you’d like the facility to update this data from the quickedit box whilst viewing the list of comments, you’ll need a series of actions and filters. I’ve tried to make appropriate comments in the necessary places for you, though bear in mind i threw this all together for you with a small amount of … Read more

What for is the table “wp_commentmeta” exactly?

That table is essentially the same as for all of the other “meta” tables in the WordPress architecture. It holds misc. bits of extra, usually optional, information about the associated post, user, or in this case comment. You can store whatever information you need to add to a comment– perhaps a plugin wants to implement … Read more

Find out which moderator approved comment?

To record the moderator that approves the comment: function wpse_comment_moderator_log( $comment ) { global $current_user; get_currentuserinfo(); update_comment_meta( $comment->comment_ID, ‘approved_by’, $current_user->user_login ); } add_action( ‘comment_unapproved_to_approved’, ‘wpse_comment_moderator_log’ ); To display it after the comment text: function wpse_display_moderator( $comment_text, $comment ) { $approved_by = get_comment_meta( $comment->comment_ID, ‘approved_by’, true ); if ( $approved_by ) { $comment_text .= ” – … Read more