Support

Account

Home Forums Gutenberg Gutenberg – Get values from another post

Solving

Gutenberg – Get values from another post

    • PaNnoz

    • January 5, 2019 at 1:51 am

    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

    • PaNnoz

    • January 8, 2019 at 7:55 pm

    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?

    • PaNnoz

    • January 21, 2019 at 10:03 pm

    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)

    • PaNnoz

    • January 22, 2019 at 1:42 am

    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?)

    • jnicol

    • February 22, 2019 at 12:11 pm

    @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.

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.