Support

Account

Home Forums Gutenberg Look to access ACF Gutenberg block content outside the loop

Solved

Look to access ACF Gutenberg block content outside the loop

  • Hi there,

    Not sure if this is possible but basically I’m inside a custom post type archive, and I want to grab the contents of a different post by id and put it at the top of my archive. The content I want to grab is solely made up of custom gutenberg blocks that I have created in ACF. I managed to do this elsewhere, but not with ACF gutenberg blocks, only with default ones.

    I’m successfully getting the post with get_post, but echoing out the content gives me nothing. I ran parse blocks over the post_content but this gives me an array of text content but no innerHTML (which is what I used to grab the regular wordpress gutenberg blocks in another place) – I need the stuff from the block template as well as just the text – the array returned is just a bit of text and a block id with some field ids inside. Can I use these ids to render my block?

    Thanks for your help!

    • foyle

    • May 20, 2019 at 4:22 am

    echo apply_filters( 'the_content', get_post_field('post_content', $id ) );

    Replace $id with the ID of the post with the blocks you want to include. I’ve created a “header” and “footer” custom post types which I use solely for storing specific blocks I designed for said parts (which basically allows me to grab the desired “header” and “footer” posts/blocks from wherever I want).

  • Thank you! That is ideal, works perfectly!

Viewing 3 posts - 1 through 3 (of 3 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.