[ad_1]
I’ve been trying to setup a website for a friend of mine that will show live data from a spreadsheet, however, there are multiple rows in the spreadsheet that shows the frequency of appearance of birds and I only want to show the rows that show the frequency of the specific bird that is on the page.
I have tried several different methods to no avail.
Any advice in relation to this would be greatly appreciated.
Thanks in advance.
[ad_2]
This should be possible using the Google sheets API and a cron job
https://developers.google.com/sheets/api/guides/concepts
`//[get_sheet_value_please=”Cell Location”]`
`function sheet_value_shortcodePlease($atts) {`
`$API = ‘XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX’;`
`$google_spreadsheet_ID = ‘XXXXXXXXX’;`
`$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);`
`// Check if the request was successful`
`if (is_wp_error($cell_response)) {`
`return ‘Error fetching data from Google Sheets’;`
`}`
`$json_body = json_decode($cell_response[‘body’], true);`
`// Check if ‘values’ key exists in the response`
`if (isset($json_body[‘values’]) && is_array($json_body[‘values’])) {`
`// Check if the first element of ‘values’ array exists and is an array`
`if (isset($json_body[‘values’][0]) && is_array($json_body[‘values’][0])) {`
`// Check if the first element of the first sub-array exists`
`if (isset($json_body[‘values’][0][0])) {`
`$cell_value = $json_body[‘values’][0][0];`
`return $cell_value;`
`}`
`}`
`}`
`return ‘NULL’;`
`}`
`add_shortcode(‘get_sheet_value_please’, ‘sheet_value_shortcodePlease’);`
`?>`
`[get_sheet_value_please=”A5″] should be first cell, you could call every cell or I think you can do a range A5-K5 with mods. running as a function`