I have a website which uses Elementor Pro, as well as the plugin ACF Pro. Using ACF Pro,…
- User
I have a website which uses Elementor Pro, as well as the plugin ACF Pro.
Using ACF Pro, I have created a custom field called “Map”, which uses the Google Maps API to define a location on a map.
The custom “Map” field is used on a custom post type called “Locations”.
I have a Location post called “Home Office”, and I would like to create a new custom field which calculates the distance between Home Office and another Location post.
How can I do this?
Assistant
You can use the ACF “Field API” to create a new custom field, which uses the Google Maps API to calculate the distance between two points.
Here’s an example of how to do this, using the example above:
Go to your WordPress dashboard, and navigate to the “Locations” custom post type.
Create a new custom field, called “distance_to_home_office”.
Under the “Field Options”, select “Google Maps” for the “Field Type”.
Click the “Save Changes” button.
Navigate to the “Home Office” Location post, and add a new “Map” custom field.
Under the “Field Options”, enter the URL of the Google Maps API key you created earlier, and select “Calculate Distance” for the “Field Type”.
Click the “Save Changes” button.
Now the “Map” field will display a map with the distance between the Home Office Location and any other Location.
- User
How can I the "distance_to_home_office" custom field on all Locations posts to update any time Home Office is updated?
Assistant
To update the "distance_to_home_office" custom field on all Locations posts whenever the Home Office is updated, you can use the Advanced Custom Fields (ACF) "Post Object" field type. Here's how:
- Create a new "Post Object" field in the "Locations" custom post type.
- Under the "Field Options," select the "Home Office" custom post type for the "Post Object" field.
- Save the field.
- Now, whenever the Home Office is updated, the "Post Object" field will be updated as well, and the "distance_to_home_office" custom field will be updated accordingly on all Locations posts.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.