Example #1
0
 function st_cars_detail_map($attr)
 {
     if (is_singular('st_cars')) {
         $default = array('number' => '12', 'range' => '20', 'show_circle' => 'no');
         extract($dump = wp_parse_args($attr, $default));
         $lat = get_post_meta(get_the_ID(), 'map_lat', true);
         $lng = get_post_meta(get_the_ID(), 'map_lng', true);
         $zoom = get_post_meta(get_the_ID(), 'map_zoom', true);
         $class = new STCars();
         $data = $class->get_near_by(get_the_ID(), $range, $number);
         $location_center = '[' . $lat . ',' . $lng . ']';
         $data_map = array();
         $data_map[0]['id'] = get_the_ID();
         $data_map[0]['name'] = get_the_title();
         $data_map[0]['post_type'] = get_post_type();
         $data_map[0]['lat'] = $lat;
         $data_map[0]['lng'] = $lng;
         $data_map[0]['icon_mk'] = get_template_directory_uri() . '/img/mk-single.png';
         $data_map[0]['content_html'] = preg_replace('/^\\s+|\\n|\\r|\\s+$/m', '', st()->load_template('vc-elements/st-list-map/loop/car', false, array('post_type' => '')));
         $data_map[0]['content_adv_html'] = preg_replace('/^\\s+|\\n|\\r|\\s+$/m', '', st()->load_template('vc-elements/st-list-map/loop-adv/car', false, array('post_type' => '')));
         $stt = 1;
         global $post;
         if (!empty($data)) {
             foreach ($data as $post) {
                 setup_postdata($post);
                 $map_lat = get_post_meta(get_the_ID(), 'map_lat', true);
                 $map_lng = get_post_meta(get_the_ID(), 'map_lng', true);
                 if (!empty($map_lat) and !empty($map_lng) and is_numeric($map_lat) and is_numeric($map_lng)) {
                     $post_type = get_post_type();
                     $data_map[$stt]['id'] = get_the_ID();
                     $data_map[$stt]['name'] = get_the_title();
                     $data_map[$stt]['post_type'] = $post_type;
                     $data_map[$stt]['lat'] = $map_lat;
                     $data_map[$stt]['lng'] = $map_lng;
                     $data_map[$stt]['icon_mk'] = st()->get_option('st_cars_icon_map_marker', 'http://maps.google.com/mapfiles/marker_green.png');
                     $data_map[$stt]['content_html'] = preg_replace('/^\\s+|\\n|\\r|\\s+$/m', '', st()->load_template('vc-elements/st-list-map/loop/car', false, array('post_type' => '')));
                     $data_map[$stt]['content_adv_html'] = preg_replace('/^\\s+|\\n|\\r|\\s+$/m', '', st()->load_template('vc-elements/st-list-map/loop-adv/car', false, array('post_type' => '')));
                     $stt++;
                 }
             }
             wp_reset_postdata();
         }
         if ($location_center == '[,]') {
             $location_center = '[0,0]';
         }
         if ($show_circle == 'no') {
             $range = 0;
         }
         $data_tmp = array('location_center' => $location_center, 'zoom' => $zoom, 'data_map' => $data_map, 'height' => 500, 'style_map' => 'normal', 'number' => $number, 'range' => $range);
         $data_tmp['data_tmp'] = $data_tmp;
         $html = '<div class="map_single">' . st()->load_template('hotel/elements/detail', 'map', $data_tmp) . '</div>';
         return $html;
     }
 }