Skip to content

Instantly share code, notes, and snippets.

@saifsultanc
Created January 27, 2025 13:22
Show Gist options
  • Save saifsultanc/12bde9ea561cc5c988fe766dcf459150 to your computer and use it in GitHub Desktop.
Save saifsultanc/12bde9ea561cc5c988fe766dcf459150 to your computer and use it in GitHub Desktop.
Populate ACF Map Address back to GF Address field
<?php
add_filter( 'gppa_get_input_values', function ( $value, $field, $template, $objects ) {
$parts = array_map( 'trim', explode( ',', $value ) );
$field_id = $field['id'];
preg_match( '/^' . preg_quote($field_id, '/') . '\.(\d+)$/', $template, $matches );
$tag = $matches[1];
switch( $tag ) {
case '1': // Street Address
$value = $parts[9];
break;
case '2': // Address Line 2
$value = $parts[10];
break;
case '3': // City
$value = $parts[12];
break;
case '4': // State
$value = $parts[13];
break;
case '5': // ZIP code
$value = $parts[15];
break;
case '6': // Country code
$value = $parts[16];
break;
}
return $value;
}, 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment