Support

Account

Home Forums General Issues ACF Maps — Link marker to post?

Helping

ACF Maps — Link marker to post?

  • I’m playing around with a feature request for a client.

    I have added a ACF Map field.

    I’m then querying a custom post type and displaying ALL the markers on the same map.

    How can I have a info box (you click the marker and it would show some post data of some sort) and / or a just link directly to the post the marker refers to.

    This is the code I’m using to display the multiple markers:

    	<?php
    	$the_query_map = new WP_Query( array( 'post_type' => 'corps-directory', 'posts_per_page' => -1, 'order' => 'ASC', 'orderby' => 'menu_order' ) );
    
    	if($the_query_map->have_posts()) :
    	while($the_query_map->have_posts()):
    	$the_query_map->the_post();
    	$the_ID = get_the_ID();
    	$get_google_map = get_field('location', $value);
    
    	$output_map[$the_ID]['map'] = '<div class="marker" data-lat="'.$get_google_map['lat'].'" data-lng="'.$get_google_map['lng'].'"></div>';
    
    	endwhile; endif;
    	wp_reset_postdata();
    
    	?><div class="acf-map"><?php
    	foreach( $output_map as $key => $map_marker ):
    		echo $map_marker['map'];
    		endforeach;
    		?>
    	</div>
  • Hi @dtomasch

    I’m afraid this topic is more related to Google Maps than to ACF. ACF is used to get the location data (latitude, longitude, and address). If you need to add an infobox, please check this documentation: https://developers.google.com/maps/documentation/javascript/examples/infowindow-simple.

    If you need further support, please check Google Maps Community.

    I hope this makes sense. Thanks 🙂

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘ACF Maps — Link marker to post?’ is closed to new replies.