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'];
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.