Tutorial – mappress pro with custom fields?

Home Forums MapPress Support Tutorial – mappress pro with custom fields?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #13471
    zefyr
    Participant

    How 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.

    #13473
    Chris
    Keymaster

    Hi,

    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); ?>

    #13482
    zefyr
    Participant

    I 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();
    ?>
    #13483
    Chris
    Keymaster

    Hi,

    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.

    #13488
    zefyr
    Participant

    I’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;">

    #13489
    Chris
    Keymaster

    Hi,

    If you use only one map/poi per post, then this should work for post ID 1234:

    mapp0.getPoiById(1234);

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.