I am interested in displaying the top 3 stories in the past week based on the total number of shares on Facebook and Twitter. I have found that these share counts are more useful indications of what is popular in comparison to sorting by the number of comments using 'orderby' => 'comment_count'
.
So my question is: What is the best way to sort posts based on the number of Facebook or Twitter shares? I’m a little concerned about the number of requests to the Facebook and Twitter APIs if I were to check the number of shares for all of the posts in the past week, and then go from there. Thanks in advance!
This is a bit of a multi-part question, so you’re getting a multi-part answer.
Working example which has 4 shares as of this writing: https://graph.facebook.com/http://ottopress.com/2011/wp-quickie-adding-chrome-voice-search/
One thing I didn’t document there was that if you leave the callback parameter blank, you get back a json object without the JSONP callback stuff.
Working example which has 29 twitter count as of this writing: http://urls.api.twitter.com/1/urls/count.json?callback=&url=http://ottopress.com/2011/wp-quickie-adding-chrome-voice-search/
Once you have the data, and have stored it in a postmeta for each post in question, then selecting based on it is a matter of using the meta_key in the post query, along with an orderby=meta_value_num parameter. This will allow you to select posts and order them by the value you’re storing in the postmeta.
Do you mean calendar week or rolling week (previous seven days) ? How many posts are we talking about?
I’d try something like this:
This is just one of many ways to do it, it depends a lot on how likely you are to stress out API – the faster you are running out of available requests the more logic and caching you need to consider and implement.