How do I embed a single row of a spreadsheet?

[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]
2 Comments
  1. `//[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`

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer