Opened 3 years ago
Closed 3 years ago
#55755 closed defect (bug) (worksforme)
Enabling REST API on custom post type cause featured to be invisible on post, page, custom post type
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 5.9.3 |
Component: | General | Keywords: | |
Focuses: | Cc: |
Description
When we enable REST API on custom post type with code below
'show_in_rest' => true,
'rest_base' => 'themes',
'rest_controller_class' => 'WP_REST_Posts_Controller',
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments'),
After this, we get Gutenberg editor on custom post type but the featured image option is gone https://prnt.sc/NetNDxFICy9e
Change History (3)
#2
@
3 years ago
- Severity changed from normal to critical
Hi @marcbelletre
It is not only with index.php issue. On a fresh WordPress install it is not working. I tried on default WordPress theme too and still featured image section not shown.
#3
@
3 years ago
- Milestone Awaiting Review deleted
- Resolution set to worksforme
- Severity changed from critical to normal
- Status changed from new to closed
This is caused by setting the rest_base
to themes
. Both theme and themes are reserved terms in WordPress.
To determine if the current theme supports post thumbnails, WordPress loads the rest endpoint http://wp-dev.local/wp-json/wp/v2/themes?context=edit&status=active&_locale=user
.
Setting your CPT's rest endpoint to themes
causes the endpoint to be replaced so the editor is unable to determine thumbnail support.
I've closed this ticket as worksforme
as registering a CPT without using the reserved term displays the thumbnail panel as expected.
Hi @bikram_sth,
I just ran into the exact same issue and finally figured it out. For some reason the featured image stopped working when enabling the block editor with
'show_in_rest' => true
The problem was that I had deleted by mistake the
index.php
file in my theme. Putting it back restored the featured image feature in the Gutenberg editor.