Skip to content

Instantly share code, notes, and snippets.

@lkhedlund
Created July 7, 2020 20:23
Show Gist options
  • Save lkhedlund/bb4e932485dfeca456656fc9d5f91e12 to your computer and use it in GitHub Desktop.
Save lkhedlund/bb4e932485dfeca456656fc9d5f91e12 to your computer and use it in GitHub Desktop.
<?php
class Place_Reviews {
// URL to the Google Place API
protected $apiUrl = 'https://maps.googleapis.com/maps/api/place/details/json';
// Google Place ID
protected $place_id;
public function __construct($place_id)
{
$this->place_id = $place_id;
add_shortcode('get-review', array($this, 'shortcode'));
}
public function getPlaceRating()
{
$place_id = $this->place_id;
$url = add_query_arg( array(
'place_id' => $place_id,
'fields' => 'rating',
'key' => '' # API KEY HERE
), 'https://maps.googleapis.com/maps/api/place/details/json' );
$json = wp_remote_get($url);
$details = json_decode($json['body']);
if ( isset( $details['result']['rating'] ) ) {
return $details['result']['rating'];
#update_post_meta( $post_id, '_star_rating', $meta_field, true );
}
}
public function shortcode()
{
// Contents of this function will execute when the blogger
// uses the [shortcode_name] shortcode.
}
}
$place_id = ''; # PLACE ID
$PlaceReviews = new Place_Reviews($place_id);
$meta = $PlaceReviews->getPlaceRating();
echo $meta;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment