get_post_status_object()WP 3.0.0

Gets the data object of the specified post status.

The post status is registered by the function register_post_status(), this function retrieves the data object obtained after the post status registration.

Uses the global variable $wp_post_statuses, which stores an array of post status objects.

Also see the hooks that trigger when the post status changes: wp_transition_post_status().

1 time — 0.000001 sec (speed of light) | 50000 times — 0.09 sec (speed of light) | PHP 7.2.16, WP 5.2.2

No Hooks.

Returns

stdClass|null. The status object.

Usage

get_post_status_object( $post_status );
$post_status(string) (required)

Name of the registered post status.

List of statuses that are registered in WordPress by default:

  • publish - published post (page or post type).
  • pending - post under review before publication.
  • draft - draft post.
  • auto-draft - just created post, still without title, content, and other information.
  • future - post scheduled for future publication.
  • private - post not accessible to unauthorized users.
  • inherit - revision or attachment (revision or attachment). See get_children().
  • trash - post in the trash.

See the entire list of statuses in the code of the function create_initial_post_types(), where WP registers the default statuses.

Examples

0

#1 See what the function returns for different post statuses

$post_status_obj = get_post_status_object( 'draft' );

/*
stdClass Object(
	[label] => Draft
	[label_count] => Array
		(
			[0] => Draft (%s)
			[1] => Drafts (%s)
			[singular] => Draft (%s)
			[plural] => Drafts (%s)
			[context] =>
			[domain] =>
		)

	[exclude_from_search] =>
	[_builtin] => 1
	[public] =>
	[internal] =>
	[protected] => 1
	[private] =>
	[publicly_queryable] =>
	[show_in_admin_status_list] => 1
	[show_in_admin_all_list] => 1
	[name] => draft
)
*/
$post_status_obj = get_post_status_object( 'publish' );

/*
stdClass Object(
	[label] => Published
	[label_count] => Array
		(
			[0] => Published (%s)
			[1] => Published (%s)
			[singular] => Published (%s)
			[plural] => Published (%s)
			[context] =>
			[domain] =>
		)

	[exclude_from_search] =>
	[_builtin] => 1
	[public] => 1
	[internal] =>
	[protected] =>
	[private] =>
	[publicly_queryable] => 1
	[show_in_admin_status_list] => 1
	[show_in_admin_all_list] => 1
	[name] => publish
)
*/
$post_status_obj = get_post_status_object( 'auto-draft' );

/*
stdClass Object(
	[label] => auto-draft
	[label_count] => Array
		(
			[0] => auto-draft
			[1] => auto-draft
			[singular] => auto-draft
			[plural] => auto-draft
			[context] =>
			[domain] =>
		)

	[exclude_from_search] => 1
	[_builtin] => 1
	[public] =>
	[internal] => 1
	[protected] =>
	[private] =>
	[publicly_queryable] =>
	[show_in_admin_status_list] =>
	[show_in_admin_all_list] =>
	[name] => auto-draft
)
*/

Notes

Changelog

Since 3.0.0 Introduced.

get_post_status_object() code WP 6.9.1

function get_post_status_object( $post_status ) {
	global $wp_post_statuses;

	if ( ! is_string( $post_status ) || empty( $wp_post_statuses[ $post_status ] ) ) {
		return null;
	}

	return $wp_post_statuses[ $post_status ];
}