I'm having some troubles with CPTs defined with custom rest_namespace
at register_post_type
. I keep getting an 404 error at the console. The error shows that the namespace is not being changed in autosave route.
WP default namespace: wp/v2
Custom namespace defined: ek/v1
I dug into the core classes to find how Wordpress handle custom namespace.
The WP_REST_Autosaves_Controler
define the namespace
using get_post_type_object
at the __construct
method:
...
$post_type_object = get_post_type_object( $parent_post_type );
....
$this->namespace = ! empty( $post_type_object->rest_namespace ) ? $post_type_object->rest_namespace : 'wp/v2';
...
If I do a discovery request at the ek/v1
I can see the endpoints registered correctly:
"/ek/v1/releases/(?P<parent>[\\d]+)/autosaves/(?P<id>[\\d]+)"
But in the console this error pops up:
GET http://localhost:8888/wp-json/wp/v2/releases/70/autosaves?context=edit&_locale=user 404 (Not Found)
So, why the default namespace persist if I did all right? Would it be some javascript function of wordpress that would be doing the request on the incorrect route? What function? How to fix it?
wp/v2
namespace toek/v1
? As well as the PHP code you've used to do this?