Display Combined Comments Count Of Facebook and WordPress Comments On Blog

Our team was struggling to find out a way to display the combined comments count of Facebook and WordPress Commenting system simultaneously on our Blog site www.preetisblog.com.

In order to show comments from both the WordPress and Facebook Commenting system simultaneously, we had installed the Facebook for WordPress plugin and we had disabled comments, yeah we repeat disabled the comments from the plugin. And we had manually inserted facebook comments box in the footer of the page using a text widget, so that we could have comments from both the systems simultaneously on our page/ posts.

Now though we had the comments from both systems, but the comments count shown at various places was that from only the WordPress Comments system, for example in the bubbles showing comments count in theme twenty eleven or number of replies below the posts. Thus, it gave a very wrong impression to a new visitor to the site as regards to the number of comments. To solve this we tried to search the internet but we could not get a simple and viable solution.

Thus as we wanted to correct this, we found a very simple solution, which we are sharing here for all fellow WordPress Administrators/ Designers. Just copy and paste the code below at the end of “functions.php” file of your active theme and you will see the combined count of comments from Facebook and WordPress at all places, wherever your theme shows the comments count. We will request all fellow developers to share this post to make the life of our good friends in similar jobs easier.


/**********************************************************
*Function to display the combined comments count of facebook
*and WordPress Comments Works with Facebook for wordpress
*plugin installed. Just copy and paste this code at the
*end of the functions.php file of your active theme or into
*that of your child theme.
*Written by www.Preetisblog.com
*We may extend this to comments of other social
*plugins like google, twitter etc graduallly.
**************************************************************/
add_filter( 'get_comments_number', 'full_comment_count_preetisblog' );
// Get combined FB and WordPress comment count
function full_comment_count_preetisblog() {
global $post;
$url = get_permalink($post->ID);
global $facebook;
$cmnts = $facebook->api('?ids='.$url,'GET');
$fbcount = $cmnts[$url]['comments'];
$post_id = $post->ID;
$mypost = get_post($post_id);
if ( ! isset($mypost->comment_count) )
$wpCount = 0;
else
$wpCount = $mypost->comment_count;
$realCount = $fbcount + $wpCount;
if ($realCount == 0 || !isset($realCount)) {
$realCount = 0;
}

return $realCount;
}

2 thoughts on “Display Combined Comments Count Of Facebook and WordPress Comments On Blog

Leave a Reply

You may also connect using:
login to preetisblog.com using facebook