Support

Account

Home Forums General Issues Render multiple markers from Custom post onto a map Reply To: Render multiple markers from Custom post onto a map

  • <?php 
    
    $posts = get_field('relation');
    
    if( $posts ): ?>
    	<div class="acf-map">
    		<?php foreach( $posts as $p ): // variable must NOT be called $post (IMPORTANT)?>
    		<?php $location = get_field('spot_lieu', $p->ID);  ?>
    
    			<div class="marker" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>">
    			<h4><?php echo get_the_title( $p->ID ); ?></h4>
    			<p class="address"><?php echo $location['address']; ?></p>
    			<p><?php echo get_the_post_thumbnail($p->ID); ?></p>
    			</div>
    
    		<?php endforeach; ?>	
    	</div>
    	
    	<ul>
    	<?php foreach( $posts as $p ): // variable must NOT be called $post (IMPORTANT) ?>
    	    <li>
    	    	<a href="<?php echo get_permalink( $p->ID ); ?>"><?php echo get_the_title( $p->ID ); ?></a>
    	    	<span><?php the_field('spot_lieu', $p->ID); ?></span>
    	    	 <p><?php echo get_the_post_thumbnail( $p->ID); ?> 
    </p>
    	    </li>
    	<?php endforeach; ?>
    	</ul>
    
    <?php endif; ?>