Support

Account

Home Forums Front-end Issues Display Maps on Front-End Reply To: Display Maps on Front-End

  • Hi,

    Using this code:

    $map_posts = get_posts(array(
        'post_type' => 'post',
        'cat' => '8'
    ));
    
    if( $map_posts ): ?>
        <div class="acf-map">
            <?php foreach( $map_posts as $map_post ) : 
    
                $location = get_sub_field('location', $map_post->ID);
    
                ?>
                <div class="marker" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>">
                    <h4><?php the_sub_field('title'); ?></h4>
                    <p class="address"><?php echo $location['address']; ?></p>
                    <p><?php the_sub_field('description'); ?></p>
                </div>
        <?php endforeach; ?>
        </div>
    <?php endif; ?>

    Is there a way to show nearby locations? Like by a radius of 20 miles, for example?

    P.s. Thank you so much for the code, it works great!