#55: WPMU Sitewide Tags Plugin Modification
Still about Wordpress MU plugin. I use Donncha’s Sitewide Tags Plugin to display all recent post from the whole users. The problem is, the comment count is displayed in the wrong way. It is always display 0 (zero), even there is a comment in the original post.
Search in the core code, and found this :
return apply_filters('get_comments_number', $count);
in the comment-template.php file. Voila, we can change how WP display the number of comment.
I add these lines into that plugin, and it works very well … Great WP !
function sitewide_tags_get_comments_num($count)
{
global $blog_id,$wpdb,$post;
$tags_blog_id = get_site_option('tags_blog_id');
if (!$tags_blog_id || $blog_id!=$tags_blog_id) return $count;
$base = $wpdb->base_prefix;
list($post_blog_id,$post_id) = explode('.', $post->guid);
$r = $wpdb->get_col(\"SELECT comment_count FROM $base{$post_blog_id}_posts WHERE ID=$post_id\");
if (is_array($r)) return $r[0];
return $count;
}
add_filter('get_comments_number', 'sitewide_tags_get_comments_num');
You probably need to also modify the Donncha’s core, remark this line :
$post->comment_status = 'closed';
to make the comment status same with the original ones.
I also have another idea to cut the post content before copy it, so the long text posting will not be displayed fully. The tags site usually for summary right ?
Hope it is usefull,

hey, thanks for your awesome code. works almost perfectly. it seems like your code is just working for all subblogs. if i add comments on my main blog though, the mainblog (index) says “no comments” even though there are comments. the comments of the subblogs get displayed like you describe it.
have you any idea why?
Comment by matt — 14 August 2009 @ 10:55 pm
if anyone wil ever find this?? this is the little thing i was talking about, just replace the following line…
if (is_array($r)) return $r[0] + $count;
Comment by matt — 19 August 2009 @ 11:50 pm
@matt: sorry, I haven’t check it.
Comment by rizapn — 30 August 2009 @ 10:41 am
I think I’ve done everything as you suggest here, but I’m still not seeing comment numbers on the main blog. The url here on my comment is the one :
http://www.storytellersunplugged.com
I’d be happy to show the php file for our plugin if someone could glance at it and see what I’ve done wrong? The PHP seems clean, no errors showing, but it’s not dragging any comments numbers. Will this only work on new comments after the change?
Comment by David — 18 October 2009 @ 8:36 am
@David: it will work for all comments, not only the new ones. Please make sure that you do all the needed modification.
Comment by rizapn — 18 October 2009 @ 12:02 pm