Overview
By default, WordPress stores a block’s field data inside the block’s HTML comment in post_content
. This is usually fine, but you may also want to create an ACF Block that saves and reads its data from post meta instead, thus making it easier to query. This doc outlines how to save the content of an ACF Block in post meta instead of post_content
.
The ability to save field data from ACF Blocks in post meta was introduced in ACF PRO 6.3. This enables you to, for example, create a custom post type with a locked block template. This lets you replicate an experience similar to the classic editor, where only your block exists to enter specific structured data. This data would then be stored in post meta and allow you to query it easily.
Usage
ACF Blocks default to the WordPress method of storing the block’s data, so you will have to make adjustments to the block.json
file to enable storing in post meta.
The usePostMeta: true
attribute is added to the ACF key section of your block.json
file:
{
"name": "acf/testimonial",
"title": "Testimonial",
"description": "A custom testimonial block that uses ACF fields.",
"style": [ "file:./testimonial.css" ],
"category": "formatting",
"icon": "admin-comments",
"keywords": ["testimonial", "quote"],
"acf": {
"mode": "preview",
"renderTemplate": "testimonial.php",
"usePostMeta": "true"
},
"supports": {
"anchor": true
}
}
Supercharge Your Website With Premium Features Using ACF PRO
Speed up your workflow and unlock features to better develop websites using ACF Blocks and Options Pages, with the Flexible Content, Repeater, Clone, Gallery Fields & More.