I use the following code to register the "media" post type.
function cw_post_type() {
register_post_type( 'media',
// WordPress CPT Options Start
array(
'labels' => array(
'name' => __( 'Media' ),
'singular_name' => __( 'Media' )
),
'has_archive' => true,
'public' => true,
'rewrite' => array('slug' => 'media'),
'show_in_rest' => true,
'supports' => array('editor', 'title')
)
);
}
add_action( 'init', 'cw_post_type' );
But this will show me a blank page.
I found that a request to /index.php?rest_route=/wp/v2/media/6&context=edit&_locale=user
got a 404 with the following response.
{
"code": "rest_post_invalid_id",
"message": "Invalid post ID.",
"data": {
"status": 404
}
}
If I set the 'show_in_rest'
to false
, it works, but that way the gutenberg editor won't shown up.
And if I changed the custom post type name 'media'
to any other name, it works again.
Anyone know how to solve this problem?
By the way, I've tried this on a fresh installation of WordPress with it's default theme with out any plugins enabled.