Skip to content

Instantly share code, notes, and snippets.

@cjbell
Created December 17, 2012 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjbell/4322604 to your computer and use it in GitHub Desktop.
Save cjbell/4322604 to your computer and use it in GitHub Desktop.
Get Cached Wordpress Tweet
<?php
function get_cached_tweet($name){
$cache_name = $name . "_tweets";
if ( false === ($tweet = get_transient($cache_name))) {
// Get tweets
$site = "https://api.twitter.com/1/statuses/user_timeline.json?screen_name=".$name."&count=1";
$result = wp_remote_get($site);
$json = $result['body'];
if (!is_a($json, WP_Error)) {
$tweet = json_decode($json);
}
set_transient($cache_name, $tweet, 600);
}
return $tweet;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment