Code snippet to create regular ACF Google Map entry in DB from an ACF Repeater Google Map Sub Field
$10-30 USD
Imefungwa
Imechapishwa over 2 years ago
$10-30 USD
Kulipwa wakati wa kufikishwa
I want to create a snippet which would take repeater field data from a Google Map subfield using the code like from the links below and then create new regular ACF Google Map fields with that looped through data.
Those now multiple extra Google Map fields would be hidden from the front end and only exist in the db to be available for query by mapping plugins.
Using this code for the looping:
```
<?php if( have_rows('locations') ): ?>
<div class="acf-map" data-zoom="16">
<?php while ( have_rows('locations') ) : the_row();
// Load sub field values.
$location = get_sub_field('location');
$title = get_sub_field('description');
$description = get_sub_field('description');
?>
<div class="marker" data-lat="<?php echo esc_attr($location['lat']); ?>" data-lng="<?php echo esc_attr($location['lng']); ?>">
<h3><?php echo esc_html( $title ); ?></h3>
<p><em><?php echo esc_html( $location['address'] ); ?></em></p>
<p><?php echo esc_html( $description ); ?></p>
</div>
<?php endwhile; ?>
</div>
<?php endif; ?>
```
I don't need the display part of it. I want that when repeater field data is entered into the Google Map sub field of the repeater field, it creates a new entry as a regular ACF Google Map field entry in the db.
Can anyone help?
I see these code examples for the looping part.
[login to view URL]
[login to view URL]
ACF Support said: You can use the get_field() function to retrieve the repeater data and use basic array operations to retrieve 'lat' and 'lng' from the location field instead of creating new fields. However, if your mapping solutions require separate ACF fields, I would recommend you take advantage of the acf/save_post callback to update the fields with the data contained in offset 'lat' and 'lng' from the location field.
Hello, I am wordpress developer working for local company in Serbia. We are working only on wordpress projects and I am serving about 20 clients from all over the world. Now I have time to work on something out of the company.
I am definitelly sure I can do whatever you need in wordpress but I am not sure I understand this task completely, specially the part about maping plugins which are going to use those fields. That is very important part because I need to know what those plugins expect to find in the database. The rest is easy. I can hook on acf/save_post event and pick up all the fields from that post ( location field ) and save whatever is needed inside wp_postmeta table. Let me know if you are interasted in cooperation. Thanks
Hello !
I am an expert Frontend developer.
I am experienced in such as WordPress, Google Maps API, PHP, JavaScript and MySQL.
I can start right away and want to discuss in detail.
Please contact me to discuss more about this project.
Thanks