Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Multiple Google Map Post markers on single page using ACF plugin
add_filter("wpgmp_markers","add_markers",1,2);
function add_markers($markers,$map_id)
{
global $post;
//echo '<pre>'.print_r($markers).'</pre>';
$new_markers = array();
$the_query_map = new WP_Query( array( 'posts_per_page' => -1 ) );
if($the_query_map->have_posts()) :
while($the_query_map->have_posts()): $the_query_map->the_post();
$get_google_map = get_post_meta(get_the_id(),'location','true');
//print_r($get_google_map);
if(is_array($get_google_map))
{
$temp_marker = array();
$temp_marker ['location']['lat'] = $get_google_map['lat'];
$temp_marker ['location']['lng'] = $get_google_map['lng'];
$temp_marker ['title'] = get_the_title(get_the_id());
$temp_marker ['id'] = get_the_id();
$temp_marker ['address'] = $get_google_map['address'];
$temp_marker ['source'] = 'manual';
$temp_marker ['content'] = get_the_content(get_the_id());
$temp_marker ['location']['icon'] ='http://localhost/googlemap/wp-content/plugins/wp-google-map-gold/assets/images/icons/pin_green.png';
$temp_marker ['location']['city'] ='';
$temp_marker ['location']['state'] ='';
$temp_marker ['location'] ['country'] ='';
$temp_marker ['location']['onclick_action'] ='marker';
$temp_marker ['location']['redirect_custom_link'] ='';
$temp_marker ['location']['open_new_tab'] ='yes';
$temp_marker ['location']['postal_code'] ='';
$temp_marker ['location']['draggable'] ='';
$temp_marker ['location']['infowindow_default_open'] ='';
$temp_marker ['location']['animation'] ='BOUNCE';
$temp_marker ['location']['infowindow_disable']='1';
$temp_marker ['location']['zoom'] ='12';
$temp_marker ['location']['state'] ='';
$temp_marker ['extra_fields']['name']='';
$temp_marker ['extra_fields']['address']='';
$temp_marker ['extra_fields']['website']='';
$temp_marker ['extra_fields']['phone-no']='';
$temp_marker ['categories']['id']='';
$temp_marker ['categories']['name']='';
$temp_marker ['categories']['type']='category';
$temp_marker ['categories']['icon']='http://localhost/googlemap/wp-content/plugins/wp-google-map-gold/assets/images/icons/pin_green.png';
$temp_marker['listing_hook']='';
$new_markers [] = $temp_marker;
}
endwhile; endif;
//Merge two arrays into one array
$markers = array_merge($markers, $new_markers);
return $markers;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment