Home › Forums › General Issues › Getting google map field from another cpt within custom query › Reply To: Getting google map field from another cpt within custom query
Glad I found this thread! I was trying to combine a relationship field and have that place a pin on the map. Here’s the code I have that works 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; ?>
Or if that does not work here’s a link to a gist with the code: Gist
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!
❓Ever wondered when and why ACF uses JSON instead of the database? Check out our summary of the most recent session of ACF Chat Friday for the answer, and make sure to register for the next session.— Advanced Custom Fields (@wp_acf) February 23, 2023
© 2023 Advanced Custom Fields.