Home › Forums › General Issues › Save Google Map field data separately instead of serialized array › Reply To: Save Google Map field data separately instead of serialized array
Use an acf/save_post filter, get the values of the repeater/sub fields (unfomatted) and save them as a standard WP meta field
add_action('acf/save_post', 'gmf_to_standard_wp', 20);
function gmf_to_standard_wp($post_id) {
// make sure a user is being saved
if (substr($post_id, 0, 5) != 'user_')) {
return;
}
// get the user id
$user_id = intval(substr($post_id, 5);
// delete existing post meta so that we start fresh
delete_user_meta($user_id, 'user_lon');
delete_user_meta($user_id, 'user_lat');
// loop over rows and save values
if (have_rows('your-repeater', $post_id)) {
while (have_rows('your-repeater', $post_id)) {
the_row();
// get value unformatted
$data = get_sub_field('your-google-map-field', false);
// you will need to excuse me here because I
// don't know how this array is saved by ACF
// or what the indexes are, so you will need to figure
// this out. I am only guessing at "lon" and "lat"
// add each value allowing multiple values
add_user_meta($user_id, 'user_lat', $data['lat'], false);
add_user_meta($user_id, 'user_lon', $data['lon'], false);
}
}
}
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.