get_post_status_object( string $post_status ): stdClass|null

Retrieves a post status object by name.


Description

Top ↑

See also


Top ↑

Parameters

$post_status string Required
The name of a registered post status.

Top ↑

Return

stdClass|null A post status object.


Top ↑

Source

File: wp-includes/post.php. View all references

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 ];
}


Top ↑

Changelog

Changelog
Version Description
3.0.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Pixelbart

    Examples

    $obj = get_post_status_object( 'publish' );
    echo esc_html( $obj->label );

    Alternatively, it also works like this:

    global $wp_post_statuses;
    $obj = $wp_post_statuses['publish'];
    echo esc_html( $obj->label );

    print_r( $obj ) looks like this:

    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
        [date_floating] => 
        [name] => publish
    )

You must log in before being able to contribute a note or feedback.