I'm using ACF Fields plugin and attempting to create a Google Map which shows post locations, but not getting very far - the pins show up in the wrong places, and when I echo out the title of the post in the HTML bubble above the pin, it's always the same post.. but in 3 different places. I only have 2 out of 10 posts with locations at the moment, so I have no idea why 3 places are being shown.. One is in the middle of the ocean as well. However, this is the closest I've come, and I've wasted the whole day trying...
<div class="acf-map">
<?php while ( $wp_query->have_posts() ) : $wp_query->the_post();?>
<?php $location = get_field('location_map'); ?>
<div class="marker" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>"></div>
<?php endwhile; wp_reset_postdata();?>
</div>
I'd have thought this would be relatively simple to achieve, but I guess not.. but then I'm far from the best coder in the world :)
If anyone can give me any pointers on this, I'd be most grateful!
if ( $wp_query->have_posts() )
so that you don't callwp_reset_postdata()
if there are no posts found. You should also verify that$location
is an array and not an error value, and that the keys 'lat' and 'long' actually exist, if either of those assumptions fail you'll get warnings and notices in your error log or on the page – Tom J Nowell♦ Apr 25 '15 at 16:59$location['lat']
contains"><script>dangerous_javascript();</script><span data="
? You should do some debugging and show us exactly what the contents of$location
is, as well as an if statement with anelse
case so we can see when no posts were found. Lets ignore what should and shouldn't, if things were as they should, you wouldn't have opened this question – Tom J Nowell♦ Apr 26 '15 at 18:32