Skip to content

Instantly share code, notes, and snippets.

@stresslimit
Created April 27, 2011 05:09
Show Gist options
  • Save stresslimit/943745 to your computer and use it in GitHub Desktop.
Save stresslimit/943745 to your computer and use it in GitHub Desktop.
WP order posts by number of facebook likes
<?php
// get fb likes from fb graph api
// put this block in single.php, or somewhere you have $post and have setup postdata [inside a Loop]
$obj = json_decode( file_get_contents( 'http://graph.facebook.com/?id='.get_permalink() ) );
$likes = $obj->shares;
update_post_meta($post->ID, '_fb_likes', $likes, false);
// make a Loop [in a template page or whatever] to query and display posts ordered by fb like popularity
$args = array(
'meta_key' => '_fb_likes',
'orderby' => 'meta_value_num',
'order' => 'desc',
);
$posts = get_posts( $args );
foreach( $posts as $post) : setup_postdata($post);
// etc etc
endforeach;
// thanks http://peterbending.com/wordpress/how-to-order-posts-by-number-of-facebook-likes/
@natesimpson
Copy link

https://wordpress.org/plugins/wp-facebook-like-posts-order/

So can anyone please help me edit this plugin ( i'm not familar with git hub or how this works but am willing to pay )

I would like to extend and update this plugin to allow you to order post by facebook likes but inside widget include an option to select a category - so say i'm displaying a group/archive of posts by a specific category like author , basketball , college, books etc... I would like to be able to use the widget om each of the category archives but be able to show most popular post in widget with number of like with just that category not all posts...This would also arrange posts by #likes inside category archive... Please help!!! thanks!

post->ID; $data = file_get_contents('http://graph.facebook.com/?id='.$permalink); $json = $data; $obj = json_decode($json); $like_no = $obj->{'shares'}; $meta_values = get_post_meta($idpost, 'facebook_likes', true); if($like_no == null){$like_no = 0;} update_post_meta($idpost, 'facebook_likes', $like_no, false); return $content; ``` } add_action('the_content', 'update_facebook_likes'); /* query_posts('meta_key=facebook_likes&orderby=meta_value'); <iframe src="http://www.facebook.com/plugins/like.php?href=&send=false&layout=box_count&width=70&show_faces=true&action=like&colorscheme=light&font&height=90" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:75px; height:90px;" allowTransparency="true"></iframe>

*/
?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment