Synchronize the ACF map field with the map fields in “Progress Map”

Advanced Custom Fields (ACF) provides a hook called acf/update_value/name={$field_name} that allows you to modify field values before they are saved to the database. This guide will walk you through the process of using this hook to syncronize ACF map field with “Progress Map” map fields. Consequently, any changes made to the ACF map field of a post will be reflected in the corresponding “Progress Map” map fields when saving or editing the post.

In your theme’s functions.php file, add the following function that hooks into the acf/update_value filter with the specific field name.

 * Syncronize ACF map field with Progress Map
function cspm_sync_ACF_map_field_with_PM($value, $post_id, $field, $original){
	// Check if the field name matches the ACF map field
	if ($field['name'] === 'your_ACF_map_field_name') {

		if(is_array($value) && isset($value['lat'], $value['lng'])){
			update_post_meta($post_id, CSPM_LATITUDE_FIELD, $value['lat']); // Latitude
			update_post_meta($post_id, CSPM_LONGITUDE_FIELD, $value['lng']); // Longitude
				update_post_meta($post_id, CSPM_ADDRESS_FIELD, $value['address']); // Address
		 	 * Add the location to "Progress Map" */
				$CSProgressMap = CSProgressMap::this();
				$CSProgressMap->cspm_save_marker_object($post_id, get_post($post_id));

	return $value;
add_filter('acf/update_value/name=your_ACF_map_field_name', 'cspm_sync_ACF_map_field_with_PM', 10 , 4);

Important: Make sure to replace your_ACF_map_field_name with the actual name of your ACF map field.

Notice: The code provided above is crafted based on the principles outlined in the Advanced Custom Fields (ACF) documentation. Please be aware that this functionality is not a built-in feature of the “Progress Map” plugin. For comprehensive details or further information on how to effectively utilize the acf/update_value/name={$field_name} hook, we recommend referring to the official ACF documentation. Visit the ACF documentation for in-depth insights and guidelines regarding the usage of this hook in your WordPress projects.

In the same context