Hello and thank you for contacting the Toolset support.
Map markers can only be pulled from one of the above:
- A Toolset address field.
- Coordinates(latitude and longitude values)
I assume that the existing fields are single-line or number fields, if that's the case, they can't be added to the map. If you have address field or coordinates values, we can work together to build markers for them on the map.
Hi,
I could transfer the data from the individual author-fields to an address-field.
With which hook can fields be processed when the post is opened in the frontend (similar to "cred_save_data")?
Well, there is currently no hook that could let you migrate a single-line address into an address field. Toolset stores address fields in two locations. In the postmeta table, as a string, similar to other Toolset custom fields. And also in a geolocation cache table where the address is stored in a binary way as coordinates. This table is useful for:
- Distance searches.
- As a cache, so Toolset would not need to query Google Maps or Azure Maps APIs every time the address should put as a marker on a map.
I could imagine the following scenario if you have only one field that has the full address as a string:
1. Delete the existing field from Toolset custom fields definitions.
2. Make sure it is completely deleted.
3. Create an address field with the same slug.
4. Create a view of users, with a MAP and put all the results on it.
5. Visit the view in the frontend several times, to force Toolset to query the used Maps API to get these addresses coordinates. Toolset will perform at most 10 queries per minute.
Can you provide more details about the current state of your website and I'll suggest the best way to migrate this into an address field?
- How many users would you like to migrate?
- I understood that you have currently 3 fields(street, zip code, city), right? What are the types of fields? Single lines?
- How are you entering these details? From a frontend form? From the backend?
I already have some code that works.
The street, zip code and city fields are entered individually in the front-end form. The address field is then created from this in the backend.
<?php
/**
* New custom code snippet (replace this with snippet description).
*/
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
// Put the code of your snippet below this comment.
add_action('cred_save_data','func_update_address_custom_field_value',10,2);
function func_update_address_custom_field_value($post_id,$form_data) {
// if a specific form
$forms = array( 1611, 1642 );
if ( in_array( $form_data['id'], $forms) )
{
$street = get_post_meta($post_id, 'wpcf-mitglied_strasse', true);
$zip = get_post_meta($post_id, 'wpcf-mitglied_plz', true);
$city= get_post_meta($post_id, 'wpcf-mitglied_ort', true);
$address = $street." ".$zip." ".$city ;
update_post_meta($post_id, 'wpcf-mitglied_maps', $address);
}
}
I don't want to use the address saved in the post, but that of the author for maps.
In the front end, I could query the individual address data with the following code and combine them into an address field.
Let's say that you have a similar code(to the first one) that build the address and save it in a user field called (user-address). Then you can use a combination of wpv-map-marker and wpv-post-author shortcodes. https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#vf-154504
Let's assume that the map has an ID "map_5", the shortcode for the marker would be:
Keep in mind, that if you don't use an address field, Toolset will query the Google/Azure Maps API each time a map is viewed, with a limit of 10 requests/min. Because only address fields are cached in the database. This may generate additional fees to the Maps API.
If this does not help, please allow me temporary access and let me check this further. Provide more details, such as where the fields are defined? What view are you working on?
Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **
So that I don't have any problems with the MAP API, I now want to calculate the address field as an additional meta field for the user data and save it.
But my previous code does not work. I suspect it is due to the parameter "$ post_id"
function func_update_user_address_custom_field_value ($ post_id, $ form_data)
Anyway, the custom code is hooked to a form. Are you using a form to update this data?
The code uses get_post_meta and get_post_meta, which are related to posts. Are the fields saved in a user custom field or in a post custom field?
Hi,
in my code is no space.
It has probably been accidentally pasted into them by copy and paste.
But that's not my question either.
In the code that I have been using so far, I am changing a contribution form. Therefore "$ post_id"
But now I want to change the user data. I probably have to be the user ID. But how exactly do I have to capture that? I tried "$ user_id". That did not work.