Home › Forums › Add-ons › Repeater Field › Some issues with saving Google Places API Review data in Repeater field
Hello,
I have a PHP script that does the following:
– It returns a JSON object of (dynamic) Google places
– It saves this review data in a repeater field
– Next, this data is displayed in a carousel
The above works properly, there is one main issue though: it makes the pages laod extremely slow. Is there a way to speed this up? Please find the code below:
Please note: I am definitely not a PHP expert, so any help is much appreciated.
Thanks a lot!!
$response_accommodation = wp_remote_get( 'https://maps.googleapis.com/maps/api/place/details/json?placeid=<place_id>&fields=name,rating,user_ratings_total,review&key=<key>');
$place_id = get_field('google_place_id');
$response_accommodation_new = str_replace('place_id', $place_id, $response_accommodation );
$body_accommodation = wp_remote_retrieve_body( $response_accommodation_new );
$body_decoded_accommodation = json_decode($body_accommodation, true);
$place_accommodation = ( $body_decoded_accommodation['result']);
$number_reviews_accommodation = ( $place_accommodation['user_ratings_total']);
$grade_accommodation = ( $place_accommodation['rating']);
update_field('rating', $grade_accommodation);
update_field('number_reviews', $number_reviews_accommodation);
$reviews_accommodation = ( $place_accommodation['reviews']);
foreach($reviews_accommodation as $v) {
$review_rating_accommodation = $v['rating'];
$review_name_accommodation = $v['author_name'];
$review_date_accommodation = $v['relative_time_description'];
$review_text_accommodation = $v['text'];
$review_profile_photo_accommodation = $v['profile_photo_url'];
$row_accommodation = array(
'author_name' => $review_name_accommodation,
'review_date' => $review_date_accommodation,
'review_rating' => $review_rating_accommodation,
'review_text' => $review_text_accommodation,
'review_profile_photo' => $review_profile_photo_accommodation,
'review_summary' => substr($review_text_accommodation, 0,75)
);
add_row('reviews', $row_accommodation );
}
?>
If you have any other questions, please let me know!
I am looking forward to receiving your answers.
Cheers,
Hans
The topic ‘Some issues with saving Google Places API Review data in Repeater field’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.