Support

Account

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