Skip to content

Instantly share code, notes, and snippets.

Created August 19, 2013 22:24
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save PeterBooker/6274924 to your computer and use it in GitHub Desktop.
* Refreshes the Transient data.
function pb_refresh_news() {
// Make HTTP request to BBC News API.
$response = wp_remote_request( '' );
// Response is in JSON format, so decode it.
$news = json_decode( $response['body'] );
// Add custom expiry time
// MINUTE_IN_SECONDS and the other similar constants are all included in WordPress.
$news->expiry = time() + ( 5 * MINUTE_IN_SECONDS );
// Set transient with latest News data
set_transient( 'pb_bbc_news', $news, 24 * HOUR_IN_SECONDS );
return $news;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment