Support

Account

Home Forums Gutenberg Get value of ACF field in Gutenberg block Reply To: Get value of ACF field in Gutenberg block

  • Try this, you can only get the custom block section array.

    function find_from_blocks($blocks) {
        $list = array();
    
        foreach ( $blocks as $block ) {
            if ( 'acf/profit' === $block['blockName'] ) {
                // add current item, if it's a heading block
                $list[] = $block;
            } elseif ( ! empty( $block['innerBlocks'] ) ) {
                // or call the function recursively, to find heading blocks in inner blocks
                $list = array_merge( $list, find_from_blocks( $block['innerBlocks'] ) );
            }
        }
    
        return $list;
    }
    
    $post = get_post();
    $blocks = parse_blocks( $post->post_content );
    $acf_block = find_from_blocks($blocks);
                                
    $acf_data = $acf_block[0]['attrs']['data'];