您可以使用此查询来选择按用户id分组的注释计数。
SELECT user_id, COUNT( * ) AS total FROM wp_comments WHERE DATE(comment_date) = CURDATE() AND user_id <> 0 GROUP BY user_id
顺便说一下,在where变量中,应该使用$wpdb->prepare()来为变量赋值(如果将来要使用它的话)
$where = $wpdb->prepare( \'WHERE comment_date >= %s AND comment_date < %s AND user_id <> 0\', $today, $tomorrow );
此代码应适用于您:
global $wpdb;
$where = \'WHERE DATE(comment_date) = CURDATE() AND user_id <> 0\';
$sql = "SELECT user_id, COUNT( * ) AS total FROM {$wpdb->comments} {$where} GROUP BY user_id";
$comment_count = $wpdb->get_results($sql, "ARRAY_A");
if( !empty( $comment_count ) ) {
foreach ( $comment_count as $count ) {
$user = get_userdata($count[\'user_id\']); ?>
<a href="<?php echo site_url().\'/author/\' . $user->data->user_login; ?>"><?php echo $user->data->display_name; ?></a><?php
}
}