最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

custom post types - WordPress Rest API only returns content when posttype has editor capability

programmeradmin4浏览0评论

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
        ]);
发布评论

评论列表(0)

  1. 暂无评论