I use Advanced Custom Fields (ACF) to store data in a custom field. I had latitude and longitude information stored separately, but I they need to be in one custom field so I made the function below. $query
just queries all the relevant posts.
<?php
$query = query_custom_posts(); if($query->have_posts()):
while ($query->have_posts()): $query->the_post();
if(get_field('map_lat') && get_field('map_lng')):
$lat = get_field('map_lat');
$long = get_field('map_lng');
$coord = $lat.','.$long;
$post_id = get_the_ID();
update_post_meta($post_id, 'map_coor', $coord);
endif; endwhile; wp_reset_query(); endif;
?>
Now the function above works. The field map_coor gets populated with the lat and long separated by a comma (I can see the information in the field).
The weird thing is that if I use get_field('map_coor')
on the front-end nothing shows up. If I save the corresponding post, then the info DOES show up.
In the function above I also tried to use the function update_field
(from ACF) like this: update_field($post_id, 'map_coor', $coord)
but the problem is still there.
So my question is; do I need to alter the function above or just run a function which saves all posts? If the latter is the case; how do I do that? I’ve found the hook save_posts
but I’m not sure how to let it run through all the posts.