Skip to content

Instantly share code, notes, and snippets.

@Neolot
Last active December 15, 2015 09:58
Show Gist options
  • Save Neolot/5241844 to your computer and use it in GitHub Desktop.
Save Neolot/5241844 to your computer and use it in GitHub Desktop.
WORDPRESS Количество лайков по URL
<?php
/*
* Кол-во лайков по URL
*/
function getFBLikes($postID){
$cache = get_transient('likes_' . $postID);
if ( empty( $cache ) ){
$url = get_permalink($postID);
$result = json_decode(file_get_contents("http://api.facebook.com/method/fql.query?query=select%20total_count%20from%20link_stat%20where%20url='$url'&format=json"));;
set_transient('likes_' . $postID, $result[0]->total_count, 3600);
return $result[0]->total_count;
} else {
return $cache;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment