Reply To: Tutorial – mappress pro with custom fields?

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

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