To coincide with this week’s WordPress 5.9 release, ACF PRO v5.12-beta1 is now available with support for WordPress 5.9’s Full Site Editor and Block Themes. 🎉🥳
This is our first beta release since we took over stewardship of ACF. The release contains significant changes to ACF Blocks in order to support the structure of the new WordPress Full Site Editor. This new editor works differently to the rest of the block editor views by loading blocks inside of an iframe which is outside of the scope of the rest of the DOM. We’re keen to gather your feedback as you start to develop Block Themes using ACF.
The release features:
To access this release, please login to your account, navigate to the “Licenses” page and select version “5.12-beta1” from the available downloads.
We’ve also introduced changes which let you use ACF Blocks inside Query Loop blocks, to display data for the currently displayed post in the loop. This means you can use ACF Blocks as a bridge between PHP templates for posts and the block editor without necessarily using any fields on the block itself.
Here’s the headline changes you need to know about:
In releases prior to ACF 5.12, use of
$post_id inside a block template would not be consistent. It would be null in the block editor, but return the
$post_id of the container post when rendered on the frontend. In ACF 5.12, there is now a consistent use of
$post_id across backend and frontend views of blocks, which is dependent on the context in which the block is used. A new
$context variable is available inside the block template which provides more information about where the block is being displayed.
If used inside a Query Loop block,
$post_id will be the post ID of the current post displayed inside the loop, and a new variable,
$context['hostPostId'] will contain the post ID of the container post which contains the Query Loop block. This allows you to access any fields on that container post.
For all other uses of blocks,
$post_id will be the post ID of the container post.
As before, by default
the_field() will return block field values. To access fields from the post, you need to use pass in the post ID, for example:
Editing a field assigned to a block used inside a Query Loop block will apply that change to every post inside the loop, as the block only exists once but is duplicated for each post in the loop.
$contextvariable may not be available in preloaded blocks.
acf_update_setting( 'preload_blocks', false );in the
Please download and test out the beta of ACF PRO 5.12. We’d really appreciate any feedback!