$post_type =
get_post_type();
$filter_block_context =
static function( $context ) use ( $post_id,
$post_type ) { $context['postType'
] =
$post_type;
$context['postId'
] =
$post_id;
return $context;
};
// Use an early priority to so that other 'render_block_context' filters have access to the values.
add_filter( 'render_block_context',
$filter_block_context, 1
);
// Render the inner blocks of the Post Template block with `dynamic` set to `false` to prevent calling
// `render_callback` and ensure that no wrapper markup is included.
$block_content =
( new WP_Block( $block_instance ) )->
render( array
( 'dynamic' => false
) );
remove_filter( 'render_block_context',
$filter_block_context, 1
);
// Wrap the render inner blocks in a `li` element with the appropriate post classes.
$post_classes =
implode( ' ',
get_post_class( 'wp-block-post'
) );
$content .= '<li class="' .
esc_attr( $post_classes ) . '">' .
$block_content . '</li>';
} /*
* Use this function to restore the context of the template tags
* from a secondary query loop back to the main query loop.
* Since we use two custom loops, it's safest to always restore.
*/