Support

Account

Home Forums Gutenberg Parsing ACF Gutenberg block from another page

Helping

Parsing ACF Gutenberg block from another page

  • 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, but it’s wrong:

    if ( function_exists( 'get_field' ) ) {
    	$pid = get_post( 11 );
    	if ( has_blocks( $pid_content ) ) {
    		$blocks = parse_blocks( $pid->post_content );
    		foreach ( $blocks as $block ) {
          // field name from my block is called, name
          $name = $block['attrs']['data']['name'];
    			if ( $block['blockName'] === 'acf/business-info' ) {
            echo $name;
          }
    		}
    	}
    }
  • Hello Amigo,

    you mean something like this?

    $content = get_the_content(false, false, 11);
    $myblocks = parse_blocks($content);
    foreach($myblocks as $block){
    	if($block['blockName'] == 'acf/business-info'){
    		echo render_block($block);
    	}
    }
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Parsing ACF Gutenberg block from another page’ is closed to new replies.