Make WordPress Core

Opened 6 years ago

Closed 5 years ago

#44119 closed enhancement (wontfix)

WP API post status queries don't work with custom public post stati

Reported by: hurtige's profile hurtige Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.9.5
Component: REST API Keywords:
Focuses: Cc:


The WP API only allows unpriv list requests to the posts controller for the publish status.

Shouldn't custom post stati with 'public' => true, 'private' => false be query-able like so?


Currently, requests for posts with a custom post stati result in:

{"code":"rest_invalid_param","message":"Invalid parameter(s): status","data":{"status":400,"params":{"status":"Status is forbidden."}}}

I've tested this behavior with the Codex provided custom post type example:

register_post_status( 'unread', array(
	'label'                     => _x( 'Unread', 'post' ),
	'public'                    => true,
	'exclude_from_search'       => false,
	'show_in_admin_all_list'    => true,
	'show_in_admin_status_list' => true,
	'label_count'               => _n_noop( 'Unread <span class="count">(%s)</span>', 'Unread <span class="count">(%s)</span>' ),
) );

and tracked this back to sanitize_posts_statuses in WP_REST_Posts_Controller which assumes all post stati that differ from the default (publish) must be private and require edit_posts

Change History (3)

This ticket was mentioned in Slack in #core-restapi by timothybjacobs. View the logs.

5 years ago

#2 @TimothyBlynJacobs
5 years ago

  • Keywords close added
  • Milestone Awaiting Review deleted

Hi @hurtige,

Sorry for the delay in providing a response to your ticket.

At the moment, the REST API doesn't really support custom post statuses at all. For a bit of background see,

I think it is unlikely that adjustments will be made to this area on an ad-hoc basis. As such, I'd currently recommend trying to override the sanitize function using the rest_{$this->post_type}_collection_params filter to support your use case.

#3 @desrosj
5 years ago

  • Keywords close removed
  • Resolution set to wontfix
  • Status changed from new to closed

Closing this out per @TimothyBlynJacobs's recommendation.

Note: See TracTickets for help on using tickets.