Skip to content

Instantly share code, notes, and snippets.

@moskowite
Created January 12, 2012 00:30
Show Gist options
  • Save moskowite/1597700 to your computer and use it in GitHub Desktop.
Save moskowite/1597700 to your computer and use it in GitHub Desktop.
function js_featured_products() {
$input = range(1,30);
$arr = array_rand($input, 4);
// for debugging
// delete_transient( 'xml_featured_products' );
if ( false === ( $xml_featured_products = get_transient( 'xml_featured_products' ) ) ) {
// It wasn't there, so regenerate the data and save the transient
// 60 seconds * 60 minutes * 24 hours = 1 day refresh or 86400 seconds
$refreshInterval = 86400;
$request_url = 'http://makershed.com/net/webservice.aspx?api_name=generic\featured_products';
$simpleXmlElem = simplexml_load_file($request_url);
$xml_featured_products = $simpleXmlElem->asXML();
set_transient('xml_featured_products', $xml_featured_products, $refreshInterval );
}
$featured_products = simplexml_load_string($xml_featured_products);
$products = $featured_products->Product;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment