Home › Forums › MapPress Support › Tutorial – mappress pro with custom fields?
- This topic has 5 replies, 2 voices, and was last updated 10 years, 2 months ago by
Chris.
-
AuthorPosts
-
October 1, 2013 at 8:30 am #13471
zefyr
ParticipantHow can I show map with data from custom fields?
I have this structure:
Contact
– Branch type 1
— Branch 1
— Branch 2
– Branch type 2
— Branch 1
— Branch 2
In Branches (Branch 1 .. Branch X) I created/use custom fields manually.I load information from Branches like title, content via custom page template.
I want show Google Maps in Contact with Points from Branches custom fields, how do I do.October 1, 2013 at 2:34 pm #13473Chris
KeymasterHi,
I’m not sure I understood your question, but if you want to show custom fields in the POI infowindow (the ‘bubble’) over each marker, you can modify the template “map_poi.php” to include them.
You can use the PHP function get_post_meta() to output the data:
<?php echo get_post_meta(postid, fieldname, true); ?>
October 2, 2013 at 10:38 am #13482zefyr
ParticipantI thought something like this:
<?php global $tpages; global $mapid; global $mpost; global $maptitle; global $mapadresa1; global $mapadresa2; global $mapadresa3; global $maplat; global $maplong; global $mymap; global $mypoi; $tpages = get_pages('child_of='.$post->ID.'&sort_column=menu_order&depth=1&parent='.$post->ID); foreach($tpages as $tpage) { $tchildren = get_pages('child_of='.$tpage->ID.'&sort_column=menu_order&depth=1'); foreach($tchildren as $tchild) { $mapid = $tchild->ID; $mpost = get_post($mapid); $maptitle = $mpost->post_title; $mapadresa1 = get_post_meta($mapid, "map-adresa1", true); $mapadresa2 = get_post_meta($mapid, "map-adresa2", true); $mapadresa3 = get_post_meta($mapid, "map-adresa3", true); $maplat = get_post_meta($mapid, "map-lat", true); $maplong = get_post_meta($mapid, "map-long", true); if (!empty($maplat) && !empty($maplong)) { $mypoi = new Mappress_Poi(array( "title" => $maptitle, "body" => "$mapadresa1, $mapadresa2, $mapadresa3", "point" => array( "lat" => $maplat, "lng" => $maplong ) )); } $pois[] = $mypoi; } } $mymap = new Mappress_Map( array( "width" => "100%", "height" => 350 ) ); $mypoi->geocode(); $mymap->pois = $pois; echo $mymap->display(); ?>
October 2, 2013 at 11:08 am #13483Chris
KeymasterHi,
I think it would be easier to let the plugin do the work instead:
1. Configure MapPress geocoding to allow it to automatically generate 1 map for each post, from the custom fields for address (or lat/lng). Save your posts to create the maps.
2. Show a mashup of the maps.
// Read $tchildren $post_ids = array(); foreach($tchildren as $tchild) $post_ids[] = $tchild->ID; $shortcode = '[mashup query="post__in=' . $post_ids . '"]'; echo do_shortcode($shortcode);
In the MapPress settings you can tell the mashup to show the address or poi contents, or you can modify the map_poi template to show other custom fields.
—
Also – you have already have code to read the grandchildren ($tchildren), but if you can think of a way to do it with a normal WordPress query you could just use the shortcode. For example, perhaps you culd assign the parent and all children to the same tag or category, then query by that tag/category.
October 3, 2013 at 6:39 am #13488zefyr
ParticipantI’ll try to rebuild with the categories.
I have one more problem, I tried link with:
<a href="#" onclick="mapp0.getPoiById('.$mapid.').open(true); return false;">Show in map</a>
But it doesn´t work.
How can I associate post ID to the POIs in map? When I used order of POI, it works.
<a href="#" onclick="mapp0.getPoi(0).open(); return false;">
October 3, 2013 at 6:45 am #13489Chris
KeymasterHi,
If you use only one map/poi per post, then this should work for post ID 1234:
mapp0.getPoiById(1234);
-
AuthorPosts
- You must be logged in to reply to this topic.