Support

Account

Home Forums ACF PRO update_field with nested groups and repater fields. Reply To: update_field with nested groups and repater fields.

  • well I tried all the possibilities without luck…
    So to fix this I used the update_post_meta function.

    $addresses = get_field( 'company', $post_id  );
    $counter = 0;
    foreach ( $addresses as $key => $address) {
    	foreach ($address as $k => $adr) {
    		$field = 'company_addresses_' . $counter . '_address_';
    		$counter++;
    		if( $adr['address']['geocode'] ){
    			$gaddress = $adr['address']['geocode']['address'];
    			if( $geocode = $this->getGeoData( $gaddress ) ){
    				$fields = [
    					'formatted_address' 	=> $geocode['formatted_address'],
    					'country' 				=> $geocode['country'],
    					'country_code' 			=> $geocode['country_code'],
    				];
    				$company = get_field('company');
    				foreach ($fields as $key => $value) {
    					update_post_meta( $post_id , $field . $key, $value );
    				}
    
    			}
    		}
    	}
    }