#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
Hi rizapn,
I’ve added your new function sitewide_tags_get_comments_num and your add_filter line just after the original line : return apply_filters. I also remarked the indicated line in Donncha’s core. But it doesn’t work, displaying 0 comment in my main blog. Do I have to delete or replace something in the comment-template.php instead of just adding your code ? Thx!
Comment by sh4rf — 1 February 2010 @ 6:13 am
I had the same problem as Matt. For some reason, the var $tags_blog_id never had a value. I kinda new to php so not exactly a wizard yet, but I modified the code a bit, and it works for me:
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);
if (!ctype_digit($post_blog_id)) return $count;
$sql = “SELECT comment_count FROM $base{$post_blog_id}_posts WHERE ID={$post_id}”;
$r = $wpdb->get_col($sql);
if (is_array($r)) return $r[0];
return $count;
}
add_filter(’get_comments_number’, ’sitewide_tags_get_comments_num’);
Comment by angelg33k — 26 February 2010 @ 8:09 pm
Guys, please give some instructions for the code. I tried it in comment-template.php, also tried it in the plugin file, but it simply doesnt work :(
Comment by Firefly — 6 April 2010 @ 9:59 pm
Hi,
I am using wordpress mu for lots of my microsites and blogs. I am facing a typical issue. I have more then 15 bloggers available on my site. Two of them are unable to see all the comments. Sometime it shows few latest comments with few articles but sometimes it’s not. There are more then 500 comments on their old articles. I was looking for support where I got solution as I need to repair my database then it’ll work. I did that but nothing has been changed. Please let me know if anyone has clue about this issue.
URLs are -
http://blogs.hindustantimes.com/shoot-at-sight/
http://blogs.hindustantimes.com/page-turner/
Thanks so much in advance.
Pradeep Pathak
Comment by Pradeep Pathak — 19 May 2010 @ 1:31 pm
Why not just put code in that function that updates main blog comment count like this:
if (is_array($r)){
$count = $r[0];
}
if( isset($post->ID) )$wpdb->query(”UPDATE wp_1_posts set comment_count=”.$count.” WHERE ID=”.$post->ID.”");
Comment by Louis Stoltz — 31 May 2010 @ 4:47 pm
Hello All,
I am kinda new to WPMU and would like to use this function to fix the comments closed message on the main blog. I added:
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
to sitewide-tags.php and I’m not sure what other changes I need to make? There is a mention above to changes to this line:
$post->comment_status = ‘closed’;
but I not sure what “to make the comment status same with the original ones” means.
I would be greatful if someone could fill in the gaps or let me know what other changes I need to make this work.
Thanks in advance!
Mike
Comment by mcfadone — 17 June 2010 @ 12:32 am
UGGS sale online
Comment by UGGS Kopen — 10 October 2011 @ 2:50 pm
‘Wrapped in a ‘gudari’ I still refer to many that I am a ‘gudari ka lal’ - a human that is affiliated with the north face jackets for women form of clothing. I loved being in that form and still love it,’ he added.
Comment by north face jackets for women — 13 October 2011 @ 12:45 pm
The Yellow Jackets capitalized on the Raider miscue five plays later, as Jack Ramey connected with Moore for a 12-yard scoring pass. Following a missed point after, the Yellow Jackets were in front 20-0 with 5:47 remaining in the opening quarter.
Comment by discount uggs — 24 October 2011 @ 9:15 am
“All of the adults were aware of the situation and were aware of the kids were being housed in the animal kennel and did nothing to stop it or report it,” he said. north face storeAll four made initial appearances in court Tuesday afternoon, and bail was set at $50,000 for each.
Comment by north face store — 27 October 2011 @ 9:17 am
the north face sale range of $22.24-$22.49 while its opening price was $22.31. The stock has
Comment by north face jackets sale — 4 November 2011 @ 4:04 pm
Interesting website. I am merely introducing The planet pandora Necklaces and also question basically also needs to sign-up precisely the same internet domain by working with hyphens concerned with the words and phrases. Really should one particular have a very long lasting re-direct towards the several other?
Comment by cheap christian louboutin — 11 November 2011 @ 12:14 pm
outside during times
Spyder Jackets For Women of intense activity, and is warm enough for very
Comment by lucylilyly — 29 December 2011 @ 2:53 pm
mastiff
say Interesting website. I am merely introducing The planet pandora Necklaces and also question basically also needs to sign-up precisely the same internet domain by working with hyphens concerned with the words and phrases.
Comment by mastiff — 1 January 2012 @ 8:37 am
chaussures louboutinI really treasure this wonderful write up. I really appreciate the information you have provided in this article. Thanks a lot!
Comment by chaussures louboutin — 23 March 2012 @ 10:50 am