Answers for "acf gutenberg data parsing"

0

acf gutenberg data parsing

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
				}
			}
		}
	}
}
Posted by: Guest on August-19-2021

Browse Popular Code Answers by Language