get_post_status_object()WP 3.0.0

Retrieve a post status object by name.

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.

Return

stdClass|null. A post status object.

Usage

get_post_status_object( $post_status );
$post_status(string) (required)
The name of a registered post status.

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.8

function get_post_status_object( $post_status ) {
	global $wp_post_statuses;

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

	return $wp_post_statuses[ $post_status ];
}