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/
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.