Hi everyone!
I am back with a small piece of code. This is the main line to retrieve all the comments recieved on all posts published by an author XXX.
<?php
$comments_count = $wpdb->get_var( "SELECT SUM(comment_count) FROM $wpdb->posts WHERE comment_count!='0' AND post_author='XXX'");
echo "<p>Comments count: {$comments_count}</p>";
?>
So if you want to retrieve a bit more information, here is how I did it:
<?php
$number = 3;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$offset = ($paged - 1) * $number;
$order_by = 'post_count'; // 'nicename', 'email', 'url', 'registered', 'display_name', or 'post_count'
$order = 'DESC';
$avatar_size = 191;
$blogusers = get_users('&offset='.$offset.'&number='.$number.'exclude='.$exclude.'&orderby='.$order_by.'&order='.$order);
$users = get_users();
$total_users = count($users);
$total_query = count($query);
$total_pages = intval($total_users / $number) + 1;
foreach($blogusers as $q) {
$u = get_the_author_meta('id', $q->ID);
$comments_count = $wpdb->get_var( "SELECT SUM(comment_count) FROM $wpdb->posts WHERE comment_count!='0' AND post_author=".$u);?>
<p><a href="<?php echo get_author_posts_url($q->ID); ?>"><?php echo get_avatar( $q->ID, $avatar_size); ?></a></p>
<p>Name: <a href="<?php echo get_author_posts_url($q->ID);?>"><?php echo get_the_author_meta('display_name', $q->ID);?></a></p>
<?php if (get_the_author_meta('description', $q->ID) != '') : ?>
<p>Description:<?php echo get_the_author_meta('description', $q->ID); ?></p>
<?php endif; ?>
<p>Posts: <?php echo count_user_posts($q->ID);?></p>
<p>Comments recieved on those posts: <?php echo $comments_count;?></p>
<p></p>
<?php } ?>
<?php
if ($total_users > $total_query) {
echo '<div id="pagination" class="clearfix">';
echo '<span class="pages">Pages:</span>';
$current_page = max(1, get_query_var('paged'));
echo paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => 'page/%#%/',
'current' => $current_page,
'total' => $total_pages,
'prev_next' => true,
'prev_text' => __('? Previous'),
'next_text' => __('Next ?'),
'type' => 'plain',
));}
echo '</div>';
?>
This one retrieves the avatar with a link to all the posts of the author, the name, number of posts created and the cound of comments recieved on them.
It also has a pagination code, so if you have plenty of users to list, you can display a limited amount at a time.
Note this is not formatted. You should display the info in divs and give some CSS rules to them.
Hope this helped someone ??