I am still in the process of learning how to use the WordPress REST API and am attempting to retrieve all posts which have been assigned the custom status "archived".
I have already created the custom status using the code below:
add_action( 'init', 'post_archived_status' );
function post_archived_status() {
register_post_status( 'archived', array(
'label' => _x( 'Archived', 'post' ),
'label_count' => _n_noop( 'Archived (%s)', 'Archived (%s)'),
'public' => false,
'exclude_from_search' => true,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'publicly_queryable' => true,
));
}
With the status now created, I tried to use this endpoint to retrieve the filtered posts but received an error message instead.
https://www.website.com/wp-json/wp/v2/posts?status=archived
{
"code": "rest_invalid_param",
"message": "Invalid parameter(s): status",
"data": {
"status": 400,
"params": {
"status": "Status is forbidden."
},
"details": {
"status": {
"code": "rest_forbidden_status",
"message": "Status is forbidden.",
"data": {
"status": 401
}
}
}
}
}
I have done some research and believe it may be something to do with authorisation however, I wouldn't have thought that would be needed as I have set publicly_queryable to true?
Any help with this is much appreciated.