i want to make custom filed that contains facebook like count for the post url
to get the likes i used this code
function fb_count(){
$link = get_permalink($post->ID);
$content = file_get_contents("http://api.facebook.com/restserver.php?method=links.getStats&urls=".$link);
$element = new SimpleXmlElement($content);
$shareCount = $element->link_stat->total_count;
return $shareCount;}
which i don’t know how to store the Facebook data in custom filed
i tried this code but it dos not work
<?php $like_key = 'likes_count';
$link = get_permalink($id);
$content = file_get_contents("http://api.facebook.com/restserver.php? method=links.getStats&urls=".$link);
$element = new SimpleXmlElement($content);
$shareCount = $element->link_stat->total_count;
$key1_values = get_post_custom_values($like_key, $id);
foreach ( $key1_values as $value )
update_post_meta($id,$like_key,$shareCount, $value); ?>
i wanna know i what i am doing wrong
I’ve done it, here is the complete code:
Just copy/paste this code into functions.php. The data will store in a custom field called likes_count. Hope it helps
For display number of Facebook fans in full text, i used this part of code :
“YOUR PAGE-ID” -> the ID of Facebook page. I hope to be useful.
See Getting Facebook Likes, Shares and Comment Counts Using PHP Function.
Its a newer version where you can get the facebook likes, comment, and share counts using facebook FQL and get it via json and display it as a text. you can manipulate the view and design it in a way you want. Its so handy, simpler Code, and soo useful