Wpdb query for comment meta for current post
You can join to the comments table and use get_the_ID(): // set the meta_key to the appropriate custom field meta key $meta_key = ‘rating_total’; $ratingtotals = $wpdb->get_var( $wpdb->prepare( ” SELECT sum(cm.meta_value) FROM $wpdb->commentmeta AS cm JOIN $wpdb->comments AS c ON (c.comment_ID = cm.comment_id) WHERE cm.meta_key = %s AND c.comment_post_ID = %d “, $meta_key, get_the_ID() ) … Read more