Created
August 19, 2013 22:24
-
-
Save PeterBooker/6274924 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Refreshes the Transient data. | |
*/ | |
function pb_refresh_news() { | |
// Make HTTP request to BBC News API. | |
$response = wp_remote_request( 'http://api.bbcnews.appengine.co.uk/stories/headlines' ); | |
// 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