How do I retrieve the ID of a (Gutenberg) block? The below code doesn’t echo the ID unfortunately.
<?php
// Retrieve the current post object
$current_post = get_post();
// Retrieve all ACF blocks for the current post
$acf_blocks = parse_blocks($current_post->post_content);
// Loop through all ACF blocks to find the blocks with the desired fields
foreach ($acf_blocks as $block) {
$block_name = $block['blockName'];
if ($block_name === 'acf/numbered-list' || $block_name === 'acf/text-image') {
$block_id = $block['id'];
$block_fields = $block['attrs']['data'];
// Check if the 'quick_link_show' field is true and display the 'quick_link_text' field value
if ($block_fields['quick_link_show']) { ?>
<a class="btn btn-accent" href="#<?= $block_id; ?>" title="Bekijk <?= $block_fields['quick_link_text']; ?>">bekijk <?= $block_fields['quick_link_text']; ?></a>
<?php }
}
}
?>