Home › Forums › Gutenberg › ACF 5.8 – Parse Gutenberg blocks and get ACF data outside of post › Reply To: ACF 5.8 – Parse Gutenberg blocks and get ACF data outside of post
Are you looking for something like this? The below would give you the data of each block item on the page and you can filter through them based on blockName or other information to target only ACF blocks.
if ( function_exists( 'get_field' ) ) {
$pid = get_post();
if ( has_blocks( $pid_content ) ) {
$blocks = parse_blocks( $pid->post_content );
foreach ( $blocks as $block ) {
var_dump( $block );
}
}
}
Keep in mind if you’re using reusable blocks the information isn’t included and only the ref ID is. I’m currently trying to get the ACF data from a ref ID so I can limit something in my footer from displaying unless the block exists on the page.
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.