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
Normally, in my footer, I’d pull ACF fields from the Contact page. That post ID is 11. I decided to use ACF Gutenberg blocks instead. The block file is called business-info.blade.php
. Therefore, business-info
is my block name. Is it possible to parse that block from my Contact page into the footer?
I thought this might work:
`
if ( function_exists( ‘get_field’ ) ) {
$pid = get_post( 11 );
if ( has_blocks( $pid_content ) ) {
$blocks = parse_blocks( $pid->post_content );
// my field called name
$name = $block[‘attrs’][‘data’][‘name’];
foreach ( $blocks as $block ) {
if ( $block[‘blockName’] === ‘acf/business-info’ ) {
echo $name;
}
}
}
}
`
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.