I have the following code in the functions.php file and I am trying to modify it so it only loads the google sheets file once a day, stores that data, and for the rest of the day the shortcode reads the data from the loaded file instead of accessing the google sheet at each page load.
function sheet_value_shortcode($atts) {
$API = 'XXX';
$google_spreadsheet_ID = 'XXX';
$api_key = esc_attr( $API);
$location = $atts['location'];
$get_cell = new WP_Http();
$cell_url = "https://sheets.googleapis.com/v4/spreadsheets/$google_spreadsheet_ID/values/$location?&key=$api_key";
$cell_response = $get_cell -> get( $cell_url);
$json_body = json_decode($cell_response['body'],true);
$cell_value = $json_body['values'][0][0];
return $cell_value;
}
add_shortcode('get_sheet_value', 'sheet_value_shortcode');
Any suggestions? Thanks a lot!