I am trying to create a custom post using WordPress REST API. The problem is that I can create the custom post when logged in as an administrator. But when I try to create the post while logged in as a custom role 'new_role', the API is giving the below error response.
{
"code": "rest_cannot_update",
"message": "Sorry, you are not allowed to edit the letter_intro custom field.",
"data": {
"key": "letter_intro",
"status": 403
}
}
And the post get created without having the post_meta
values. I tried adding the capability by adding the below code in function.php
add_action('rest_api_init', function () {
$new_role = get_role('new_role');
$new_role->add_cap('edit_post', true);
$new_role->add_cap('edit_post_meta', true);
...
...
But it is not working.