julienbechade/acf-location-field

Question: Can this return multiple locations?

Closed this issue · 7 comments

Am I able to query multiple posts and have their locations added to a single map?

Within the admin or on the front-end?
No to the first one and you can do whatever you want on the front-end because each location is returned attached to a post…

Problem fixed, apparently…

Hi Julien, sorry for abandoning this thread. I'm still not clear on how I'd use an array of locations on a single map (front-end).

What don't you get exactly?

You cannot have multiple locations returned from one field.
Instead you need to set one location per post and loop through posts to retrieve the values.

if ( have_posts() ) :   
    while ( have_posts() ) : the_post(); 

    // Retrieve the location field array w/ address and coordinates
    $location = get_field('field_name');
    // Store values in their own variables
    $coordinates = $location['coordinates'];
    $address = $location['address'];

    endwhile; // end of the loop.
endif;

Once you have this you can do whatever you want with it, just echo it, use it in a Google Maps…

Or you could use the repeater field and then loop throught it to retrieve the field values attached.
Have a look at the documentation on Elliot's site.

Did I answered your question or are you still in the fog?

Cheers.

I made it through. Thanks Julien!

Happy to hear that!

Cheers.