I want to display the Facebook comment count on my blog archives.
My wordpress site has the following php function in function.php
// Get combined FB and WordPress comment count
function full_comment_count() {
global $post;
$url = get_permalink($post->ID);
$filecontent = file_get_contents('https://graph.facebook.com/?ids=' . $url);
$json = json_decode($filecontent);
$count = $json->$url->comments;
$wpCount = get_comments_number();
$realCount = $count + $wpCount;
if ($realCount == 0 || !isset($realCount)) {
$realCount = 0;
}
return $realCount;
}
This is how I am using the function on a template file inside a loop <?php echo full_comment_count(); ?>
Most of the time most of the articles show “0” comments. But sometime one or 2 of them work. what am i doing wrong
Try this