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
if(isset($value['address']))
update_post_meta($post_id, CSPM_ADDRESS_FIELD, $value['address']); // Address
/**
* Add the location to "Progress Map" */
if(class_exists('CSProgressMap')){
$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
- Open the single post page inside a modal
- Programmatically change single map language based on the URL’s language attribute
- Set the zIndex of a specific marker
- Replace/override your map query settings to showcase diverse locations on any page
- Show locations based on a keyword search
- Display “Progress Map” metabox on “Envira Gallery” add/edit page
- How to add custom class names to the infoboxes
- How to add “Read More” link to the infobox content
- Programmatically change the content of the carousel items
- Programmatically change the content of the infobox
- Programmatically change the title of the infobox
- Make the plugin GDPR/DSGVO compliance
- Trigger marker events
- Center the map on a specific marker on page load
- Open the locations/posts “Nearby places” map inside a modal
- Redirect to the single post on marker click
- Insert a map inside a taxonomy page and display locations based on the current taxonomy term
- Use marker popups to display the post ID
- Change the text of the button “Toggle Carousel”
- Use the StreetView image as the carousel items image
- Hide the Points of Interest from the map
- Import/Export your maps between WordPress websites
- Import/Export your map locations between WordPress websites