Support

Account

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

  • Hi @james

    it looks like you solved this issue above and I was wondering if you could assist with mine its along the same lines when you have a chance.

    I have created a custom field with map loaction this is attached to a category in of posts.
    Ideally what i want to happen is elements of the post display on the map inside the pointer window when clicked.

    Im building out a wordpress site that plots custom data on a google map using Advanced Custom Fields Pro but can’t get it to generate the map using the custom page I have created.

    I have created a Google Map Picker with ACF which I have assigned to a post category type ID 4. This is functioning as expected and I can pick the location for each post

    In my custom template for wordpress site I have entered the below code to call any location information from the Category in question in this case its ID is 4

    This Section pulls and displays the location as expected on the page ( I will be hiding it in the final build)

    <?php
    $catquery = new WP_Query( 'cat=4&posts_per_page=10' );
    while($catquery->have_posts()) : $catquery->the_post();
    ?>
    
      <?php the_field('location'); ?>
    
    <?php endwhile; ?>
     </div>

    However the map just pulls the first blog and does not display the other Below is the code im using to call the location and pass it into the map

    <?php if( have_rows('sdg_location') ): ?>
        <div class="acf-map">
            <?php while ( have_rows('sdg_location') ) : the_row(); 
    
                $location = get_field('location');
    
                ?>
                <div class="marker" data-lat="<?php echo $location['lat']; ?>" 
        data-lng="<?php echo $location['lng']; ?>">
    
                </div>
        <?php endwhile; ?>
        </div>
    <?php endif; ?>

    Can you advise of a better method of doing this? Is there a way to pass the location from the categories directly into the map call?

    Thanks a million for your help in advance