Skip to content

Instantly share code, notes, and snippets.

@nikibrown
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikibrown/727b3add0a0e660706ec to your computer and use it in GitHub Desktop.
Save nikibrown/727b3add0a0e660706ec to your computer and use it in GitHub Desktop.
Combine Advanced Custom Fields Relationship field + google maps field
<?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; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment