Hi guys,
I’m working with Gutenberg, and what I’m trying to do is like the link, but then with Gutenberg.
https://www.advancedcustomfields.com/resources/how-to-get-values-from-another-post/
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?
Kind regards,
Mark
Hi all,
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).
Kind regards,
Mark
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.
Hi Kasper,
I’m afraid it’s not possible with ACF fields. I’ve added an excerpt field in the sidebar, you can retrieve that data trough the get_the_excerpt() function. The customer has to put in the introduction twice, not the best workaround, but it works :).
Kind regards,
Mark
I know I may be a little late to the party but I believe that I found a solution to this. Maybe something that was added to an update since last this was reviewed, but I did the following to get a specific field that is from a block on another post.
$postBlocks = parse_blocks($post->post_content);
print_r($postContent); // Displays array of all blocks
$postContent = $postBlocks[0]['attrs']['data']['custom_field_slug']; // Example
echo $postContent;
Hope you all are well,
Darren
The topic ‘Gutenberg – Get values from another post’ is closed to new replies.
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.