Support

Account

Home Forums ACF PRO Save certain Google Maps data into custom field Reply To: Save certain Google Maps data into custom field

  • Your approach is almost correct, but there are a few issues to address:

    The acf/update_value action does not directly pass the Google Maps field data as an associative array. You need to ensure that $value contains the data you’re expecting.

    Here’s the corrected code:

    function update_state_short( $value, $post_id, $field ) {
        // Check if the value contains the 'state_short' key
        if ( isset( $value['state_short'] ) ) {
            // Update the 'state_short' ACF field with the new value
            update_post_meta( $post_id, 'state_short', $value['state_short'] );
        }
    
        // Return the original value to ensure the ACF field is saved correctly
        return $value;
    }
    
    // Hook into the ACF update_value action for the specific field key
    add_filter( 'acf/update_value/key=field_5e5a38be195bc', 'update_state_short', 10, 3 );

    This article explains how to use the acf/update_value hook in detail. It has examples and recommendations: https://www.advancedcustomfields.com/resources/acf-update_value/