Support

Account

Home Forums Add-ons Repeater Field Some issues with saving Google Places API Review data in Repeater field

Unread

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

Viewing 1 post (of 1 total)

The topic ‘Some issues with saving Google Places API Review data in Repeater field’ is closed to new replies.