Revision: 52370
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at October 21, 2011 02:27 by florent
Initial Code
function get_fan_count(){ $fb_id = '106900272716297'; $count = get_transient('fan_count'); if ($count !== false) return $count; $count = 0; $data = wp_remote_get('http://api.facebook.com/restserver.php?method=facebook.fql.query&query=SELECT%20fan_count%20FROM%20page%20WHERE%20page_id='.$fb_id.''); if (is_wp_error($data)) { return 'whoa error!!!'; }else{ $count = strip_tags($data[body]); } set_transient('fan_count', $count, 60*60*24); // 24 hour cache return $count; } Add the this into your WordPress theme in the location you wish to display the count. <? echo get_fan_count(); ?>
Initial URL
Initial Description
Initial Title
Get Facebook Fan Count Using Get_Transient and Wp_Remote_Get
Initial Tags
wordpress, facebook
Initial Language
PHP