1

I am trying to separate Custom ACF Gutenberg Blocks from the rest of the core blocks on a post. Currently I am using the_content(); This is grabbing every block in the Gutenberg Editor. What I want to do now is look at all the blocks in the Gutenberg editor, check to see if they are a custom ACF block, and if they are an ACF block then output them else, don't output the block. What I have currently is:

$blocks = parse_blocks( get_the_content() );
foreach ( $blocks as $block ) {
    if ( 'acf/qd-center-copy' === $block['blockName'] ) {
      echo $block['innerHTML'];
    }
}

So what hte above function is doing is looping through the blocks in the Gutenberg editor, checking to see if the blockname is 'acf/qd-center-copy' if the block name equals 'acf/qd-center-copy' then output that block. The issue I am running into is the outputting of that block and I'm not sure what I need to do to output the custom ACF block properly.

Here is the what is ouputted for the block with the block name of 'acf/qd-center-copy' when I use print_r($block):

 Array
(
    [blockName] => acf/qd-center-copy
    [attrs] => Array
        (
            [id] => block_5caf50e1cda63
            [data] => Array
                (
                    [qd_background_color_toggle] => 1
                    [_qd_background_color_toggle] => field_5c700fe8bb525
                    [qd_headline] => Test Centered Text block
                    [_qd_headline] => field_5c70100ebb526
                    [qd_content] => Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
                    [_qd_content] => field_5c70101dbb527
                    [qd_additional_column_toggle] => 0
                    [_qd_additional_column_toggle] => field_5c701034bb528
                )

            [name] => acf/qd-center-copy
            [align] => 
            [mode] => auto
        )

    [innerBlocks] => Array
        (
        )

    [innerHTML] => 
    [innerContent] => Array
        (
        )

)
1

Try using the code below to display the html for your block. I found the solution here.

render_block( $block )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.