Home › Forums › MapPress Support › Geocode inside a CustomPostType › Reply To: Geocode inside a CustomPostType
November 11, 2013 at 6:21 am
#13741
Hi Connie,
The plugin doesn’t have any functionality to add geocoders in post editors.
But if you’re using MapPress to generate maps from the address, it is already geocoding each address into a lat/lng. With some PHP code you could capture those values and save them to custom fields.
I haven’t tested this code but it might help to get you started:
<?php
function mysave($post_ID, $post) {
// Get the first map & first poi for this post
$maps = get_post_map_list($post->ID);
// Get first map and its first poi
if (!empty($maps) && !empty($map[0]->pois)) {
$poi = $map[0]->pois[0];
update_post_meta($post->ID, 'my_lat', $poi->point['lat']);
update_post_meta($post->ID, 'my_lng', $poi->point['lng']);
}
}
add_action('save_post', array(&$this, 'save_post'), 110, 2);