Created
September 28, 2016 11:28
-
-
Save fcgist/4aa7f6145684b441da17039a5e98e2d0 to your computer and use it in GitHub Desktop.
Display Posts from Specific Categories on Google Maps using ACF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter("wpgmp_markers","add_markers",1,2); | |
function add_markers($markers,$map_id) | |
{ | |
global $post; | |
$new_markers = array(); | |
$the_query_map = new WP_Query( array( 'meta_key' => 'location' , 'category_name' => 'unites-states' ) ); | |
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'); | |
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 ['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'; | |
$new_markers [] = $temp_marker; | |
} | |
endwhile; endif; | |
$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