Support

Account

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;
    }
    }
    }
    }
    `