I have noticed a bug/quirk in how the ACF Post Object field type functions inside the render template for an ACF Gutenberg Block.
In short, after running setup_postdata() on a Post Object, the_field() and get_field() do not work as expected.
Here is an example ACF Block render template that demonstrates the problem:
$post_object = get_field('my_post_object_field');
if( $post_object ):
global $post; // Need to make sure we overwrite the global Post Object
$post = $post_object; // override $post
// setup_postdata() works as expected. e.g. the_title() will display
// the title of the post referred to by $post_object.
// Normally, setup_postdata() is all that is required to let ACF
// know the new post ID, so that functions such as the_field() pull
// data from the correct post.
// However the_field('my_custom_field') is broken. It tries to pull
// 'my_custom_field' from the original global $post, when it should
// be pulling from the post referred to by $post_object.
// For the_field() to work correctly we have to explicitly pass it
// the ID of our Post Object:
Please note that this quirk is specific to ACF’s Gutenberg Blocks. It does not affect ACF meta fields.
I assume that this is a scoping issue. My question: Is there a way to force ACF to recognise that it is supposed to be operating on the global $post, instead of having to explicitly pass it a post ID every time?