admin管理员组文章数量:1432620
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
(
)
)
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
(
)
)
Share
Improve this question
asked Apr 11, 2019 at 15:13
user9664977user9664977
3875 silver badges12 bronze badges
1 Answer
Reset to default 1Try using the code below to display the html for your block. I found the solution here.
render_block( $block )
本文标签: Using Gutenberg parseblocks Function With ACF Custom Blocks
版权声明:本文标题:Using Gutenberg parse_blocks Function With ACF Custom Blocks? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745585820a2664899.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论