3

I am trying to request my post via the WordPress V2 Rest API in the backend. For whatever reason the post content is only returned when my custom post type has the editor support enabled. Is there a way to get the post content in the same request without having to enable the Gutenberg Editor?

My fetch request:

    apiFetch({
        path: addQueryArgs('/wp/v2/my_custom_post_type/' + postId, {
            context: 'edit'
        })
    }).then((post) => {
        console.log(post);
    });

My post type:

        register_post_type('my_custom_post_type', [
            'labels' => [
                'name' => 'My Custom Post Types',
                'singular_name' => 'My Custom Post Type'
            ],
            'public' => false,
            'show_in_rest' => true,
            'hierarchical'=> false,
            'show_ui' => true,
            'menu_icon' => 'dashicons-grid-view',
            'supports' => [
                'revisions',

            ],
            'has_archive' => false
        ]);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.