Using ACF PRO 5.5.7 with WP 4.7.2. Rolling back to ACF 5.5.3 does not fix.
I have a function to which I pass a $post object and have simplified the function to isolate the problem:
printLinkBar($post) {
echo '<pre>';
echo '<h2>' . $post->ID . '</h2>';
$source = get_field('source', $post->ID);
echo 'source: ' . $source . '<br>';
$source2 = get_field('field_561ef519ecce4', $post->ID); // Key refers to 'source' field
echo 'source2: ' . $source2 . '<br>';
$all = get_fields($post->ID);
var_dump($all);
echo '</pre><hr>';
return;
}
I call this function repeatedly and not from within the_loop. It is always passed a post that is a custom post type.
The first time it is called, it does not output the value for the ‘source’ field and the field is missing in the value returned by get_fields.
When a newer post is created, that newer post will not have these values output and the post that didn’t work works.
The value of the field always shows up as expected in the admin.
Calling setup_postdata() doesn’t fix things.
Changing the name of the field to source2 or source3 does not fix the problem.
Simply visiting the post in the admin *sometimes* fixes it, but not always. This post type is created outside of the admin so usually they are never seen within the admin.