function – How to get postId from argument $block when register_block_type() is there?

I am trying to register custom block type in file functions.php of my block theme:

function render_custom_block($attributes, $content, $block) {
    return $block->available_context['postId'];
}
add_action('init', function() {
    register_block_type('mytheme/custom-block',
        array(
            'render_callback' => 'render_custom_block'
        )
    );
});

but instead of getting postIdi always get 1, when i try print_r($block)i see property available_context is protected and context Is Empty.

so how to get postId From $block argument ?

Leave a Comment