You can try this query that counts user comments by using the user_id
field in the comments table as a filter:
function count_user_comments_today( $uid ){
global $wpdb;
$today = date('Y-m-d');
$tomorrow = date('Y-m-d', time() + 86400);
$count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->comments} WHERE user_id = %d AND comment_date >= %s AND comment_date < %s ", $uid, $today, $tomorrow ));
return $count;
}
where we use PHP to give the current date and we don’t use any SQL date functions on each row.
You could also consider using the WP_Comment_Query class if you are looking for a more native solution.
Usage:
You can use it like this for the current logged in user:
global $current_user;
get_currentuserinfo();
echo count_user_comments_today( $current_user->ID );
and for the current author:
echo count_user_comments_today( get_the_author_meta('ID') );
in the loop in the template page author.php
.
Outside the loop in author.php
you can use:
global $wp_query;
$curauth = $wp_query->get_queried_object();
echo count_user_comments_today( $curauth->ID );
for the current author.