I’m working with Gutenberg, and what I’m trying to do is like the link, but then with Gutenberg.
I’m trying “$title = get_field(‘title’, 871);” but this isn’t working with blocks. Also tried to parse the blocks with “$blocks = parse_blocks( $post->post_content);”, but can’t get the ACF field by name.
Is this possible to do now or in the future?
Maybe there are more people running into this problem. I’ve contacted support and got the following response:
I consulted the developer and I’m afraid this is currently not possible with the gutenberg plugin.
All values within a “block” are saved within the Block JSON located within the post_content value.
Apologies for the inconvenience.
So, I’m afraid it’s not possible (yet).
Not of assistance here to the question, but curiosity… what are you trying to achieve that couldn’t be done by assigning field to the post / post type / etc like normal, whereas the block is more specifically unique to just the content within that specific post?
We use this if we want to show an introduction to children pages, on the parent page. So for example on a about us page.
I would use either the post excerpt or I would create an ACF field where content can be entered to use for this (and fall back to the WP generated post excerpt if the client did not enter content for either excerpt or the custom field)
That’s also a solution! My solution:
I’ve created a Gutenberg block, which I add on the parent page, with a repeater field. Each repeater holds an icon, title, text and button. The button can hold any link, so you can link the block to Google, but also to a child page. More freedom, but in case of a child page some more work.
I think we are discovering the difference between when we want to use a metabox and when we want to use a block. One of the values of having something stored in
postmeta is being able to retrieve it from elsewhere. I’d been hoping for something similar to the way we retrieve field values from options pages, but that doesn’t seem to work. It’s making me re-evaluate my original ideas about converting field groups to blocks. Though I bet it wouldn’t be that hard to create a block that inserted the output from a field group, even though we might not be able to do that with ACF. (Too recursive?)
@wpfangirl makes an excellent point. Although I originally assumed that blocks would completely replace custom fields, I now see that they serve very different purposes, and can co-exist.
One area that meta fields shine is that is is easy to display them outside the post’s content, or perform data operations on them: retrieving a single piece of data from another post, or comparing two dates, for instance.
Blocks, on the other hand are for formatting the main content area of a post. If your data only ever needs to be displayed on a single post, then a block might be a good fit.
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!
© 2019 Advanced Custom Fields. Subscribe