• Hi,
    I want to get blocks content into rest api.
    after reloading the editor, all blocks are disappearing. If I desactivate the REST API blocks plugin, not happening. Here a video where you can see what I mean:

    https://dashboard.thinkmoto.de/wp-content/uploads/2022/12/GUTENBERG.mov

    Also I have tried to add this code into functions.php (without the plugin), but same result as the video

    add_action('rest_api_init', function () {
        if ( ! function_exists( 'use_block_editor_for_post_type' ) ) {
            require ABSPATH . 'wp-admin/includes/post.php';
        }
        // Expose Gutenberg blocks in the WordPress REST API
        
        $post_types = get_post_types_by_support( [ 'editor' ] );
        
        foreach ( $post_types as $post_type ) {
            if ( use_block_editor_for_post_type( $post_type ) ) {
                register_rest_field($post_type, 'blocks', ['get_callback' => function ( array $post ) {
                    return parse_blocks( $post['content']['raw'] );},]);
            }
        }
    });

    Any idea how to solve the problem?
    Thanks!

  • The topic ‘Page content disappears’ is closed to new replies.