Using WordPress ‘get_post_status_object()’ PHP function

The get_post_status_object() WordPress PHP function retrieves a post status object by name.

Usage

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

Parameters

  • $post_status (string): The name of a registered post status.

More information

See WordPress Developer Resources: get_post_status_object()

Examples

Display post status label

Retrieve the post status object for ‘publish’ and display its label.

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

Check if post status is public

Retrieve the post status object for ‘draft’ and check if it’s a public status.

$post_status_object = get_post_status_object('draft');
$is_public = $post_status_object->public;

Retrieve all registered post statuses

Iterate through all registered post statuses and print their labels.

global $wp_post_statuses;
foreach ($wp_post_statuses as $post_status) {
    echo esc_html($post_status->label) . '<br>';
}

Get post status object for a specific post

Retrieve the post status object for a specific post and display its label.

$post_id = 1;
$post = get_post($post_id);
$post_status_object = get_post_status_object($post->post_status);
echo esc_html($post_status_object->label);

Check if a post status is publicly queryable

Retrieve the post status object for ‘private’ and check if it’s publicly queryable.

$post_status_object = get_post_status_object('private');
$is_publicly_queryable = $post_status_object->publicly_queryable;