Home › Forums › Front-end Issues › Relationship field & google maps › Reply To: Relationship field & google maps
found this from another post – Worked like a charm for me.
<?php $posts = get_field('featured_space'); if( $posts ): ?>
<div class="acf-map">
<?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
<?php setup_postdata($post); ?>
<?php $space_address = get_field('space_address', $post->ID); ?>
<div class="marker" data-lat="<?php echo $space_address['lat']; ?>" data-lng="<?php echo $space_address['lng']; ?>">
<h4><?php the_title();?></h4>
<p><?php echo $space_address['address']; ?></p>
</div><!--/.marker-->
<?php endforeach; ?>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
</div><!--/.acf-map-->
<?php endif; ?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.