I am trying to get the current post ID in the render_callback
function to generate related posts.
However, the global $post
object gives null.
I use this code for example from here:
add_action( 'init', function() {
register_block_type('fc/related-posts', array(
'render_callback' => function() {
global $post;
var_dump($post); // null
}
));
});
It will be fired on init
but just $wp
object works others like $wp_query
or $post
are null.
var_dump( get_post() );
too, just to make sure there isn't some odd globals scoping problem with lambdas.