I need this for a student website project. I am using Google Sheets to collect data. These data can be then dynamically edited by other users at any time. I have been using the function below (source: [login to view URL]) that I included in my [login to view URL] file to read and display values from the individual Google Sheets cells on my website:
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 = "[login to view URL]$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');
Then, I used the shortcode [get_sheet_value location="Cell Location"], e.g. [get_sheet_value location="Sheet2!C4"], in my WordPress pages to refer to the cells within the spreadsheet. The problem began when my pages contained hundreds of those shortcodes, probably by exceeding the number of allowed API calls set by Google. Therefore, I would need the above code modified in a way that it would load the Google Sheet, for example, once a day and save a fresh copy of the data somewhere on the server. Then, every time a page containing the shorcodes is loaded, it reads from the saved version of the data saved on the server instead of the actual Google Sheet.
P.S. I am not very skilled at writing PHP code.
Thanks in advance!
Hello, Your project description really caught my attention. I'm extremely interested in your project because of it's related to WordPress I am very confident to fullfill your requirement asap. I'm an expert in making new plugins for wordpress. I've great experience more than 10 years in this field.
Google Api have access limited. Your way is perfect to perform action.
Yes possible to check once in a day and save updated value to local server.
Show value anywhere by shortcode from saved one.
Well let's discuss further via chat.
Thank you
Jaypalkumar
(Plugin Expert)