I have the following problem in Wordpress.
I created a new custom post type called "coursenote". I'm using the REST API for Ajax calls (using jQuery). Creating new posts and updating posts is working fine, but deleting doesn't work.
My custom post type definition:
register_post_type( 'coursenote',
[
'labels' => [
'name' => __( 'User notes' ),
'singular_name' => __( 'User note' ),
],
'public' => false,
'show_in_menu' => true,
'show_ui' => true,
'show_in_rest' => true,
'rest_base' => 'usernote',
'has_archive' => false,
'supports' => array(
'page-attributes',
'title',
'editor',
'author',
),
]
);
The REST URL for the custom post type is "http://.../usernote". I can read, post and update, but I can't delete a post. Deleting should work via DELETE method on http://.../usernote/[id]/ (see Wordpress documentation), but I get a 403 forbidden message.
That's the jQuery Ajax code:
ajaxRequestUserNotes = jQuery.ajax({
method: 'DELETE',
url: "http://.../usernote/" + id + '?force=true',
beforeSend: function (xhr) {
xhr.setRequestHeader('X-WP-Nonce', nonce);
},
success: function (result) {
console.log(result);
}
});
As you can see, the authentication header is also set (like this it's working on new posts and updating posts).
What am I missing here?