Been waiting for years for this, but now I don’t seem to understand how to use it:
ACF 6.3 Beta 1 (apparently) has the ability to save meta fields into the database from an ACF block.
However, I have not been able to get it to work, and I’m now trying to understand what “This functionality would enable you to create a custom post type, with a locked block template, letting you replicate a classic editor-like experience 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.” means. It does sound more restricting than what I was hoping for.
Looking forward to some examples đŸ™‚
I just did some experiments and I struggle a bit with how the workflow should be.
Here’s how I did it to create block in my custom post type template.
– register_block_type(... path to folder containing block.json ...)
– My block.json looks like this
{
"name": "my-theme/template-quote",
"title": "Template Quote",
"category": "theme",
"icon": "format-quote",
"style": "wp-block-quote",
"acf": {
"usePostMeta": true,
"renderTemplate": "./template-quote.php"
}
}
– Adding a field group for this block.
– When using Editor for block theme creating a custom template, the above block was not pickable until I removed the row "usePostMeta": true
, so I added the block before adding the row again.
– This was not enough to get the block editable when editing my custom post, because it was “outside” of my “Content” block, but it shows up in when using the Template Preview functionality.
– I tried to add my custom post type to the ACF field group location rule, so it shows up for block or post type. I also changed presentation positiịn to “Side”, to get my ACF fields to show up in my custom post type sidebar in the block editor.
Final thoughts / wishes / bugs(?)
– To be able to add my block to the custom post type single template in the theme editor when usePostMeta: true, is important for my current dev workflow for building a block theme.
– Editing my custom fields in the post editor sidebar will not update the block preview. Currently I need to reload the editor after update to see my changes in preview mode.
– In Template Preview mode, I’m missing to be able to select my block to edit it – this would be awesome.
Hi, I just wanted to add a note here as it’s the only thread I’m seeing about this recent usePostMeta
feature, and I was fortunate to get to discuss some of the aspects (and limitations) of its current implementation (a/o v6.3.4) with one of the plugin developers. In particular, he noted that a block with the feature enabled must be “at the top level” in the editor and, thus, not nested in another block such as a column or group. In my current project, it would be extremely useful if one could nest one of these blocks in at least a limited set of other blocks (e.g. containers such as group, cover, and columns).
I honestly think this feature is a game-changer in that it allows combining the great editor experience provided by Gutenberg with the power of ACF fields- particularly, in associating the block fields at the post level to allow for querying by field content housed in a block within the post content. I look forward to the evolution of this great feature!
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.