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

  • My final solution to parse for reusable block data also…

    if ( function_exists( 'get_field' ) ) {
    	$pid = get_post();
    	if ( has_blocks( $pid_content ) ) {
    		$blocks = parse_blocks( $pid->post_content );
    		foreach ( $blocks as $block ) {
    			if ( $block['blockName'] === 'acf/your-block-name' ) {
    				// Access to block data
    			} elseif ( $block['blockName'] === 'core/block' ) {
    				$block_content = parse_blocks( get_post( $block['attrs']['ref'] )->post_content );
    				if ( $block_content[0]['blockName'] === 'acf/your-block-name' ) {
    					// Access to "some" block data
    				}
    			}
    		}
    	}
    }