get_post_statuses(): string[]

Retrieves all of the WordPress supported post statuses.

Description

Posts have a limited set of valid status values, this provides the post_status values and descriptions.

Return

string[] Array of post status labels keyed by their status.

More Information

Usage:
$post_statuses = get_post_statuses();

output:

Array
(
[draft] => Draft
[pending] => Pending Review
[private] => Private
[publish] => Published
)

Note:

To get an array of all post statuses, including those created with register_post_type(), see get_post_stati.

Source

function get_post_statuses() {
	$status = array(
		'draft'   => __( 'Draft' ),
		'pending' => __( 'Pending Review' ),
		'private' => __( 'Private' ),
		'publish' => __( 'Published' ),
	);

	return $status;
}

Changelog

VersionDescription
2.5.0Introduced.

User Contributed Notes

  1. Skip to note 3 content

    Note that get_post_statuses returns a hard-coded list of statuses as indicated by the code sample. This list is missing core statuses such as ‘future’.

    To actually see the list of all post statuses available in your WordPress instance, use get_post_stati (https://developer.wordpress.org/reference/functions/get_post_stati/).

  2. Skip to note 4 content

    Get all statuses including custom statuses.

    add_action('init', function () {
        global $wp_post_statuses;
        var_dump( $wp_post_statuses );
    
        // result... with 'custom_status'
        /*
        array(
            "publish",
            "future",
            "draft",
            "pending",
            "private",
            "trash",
            "auto-draft",
            "inherit",
            "custom_status" // <-- here we go
        )
         */
    
    
    }, PHP_INT_MAX); // <-- high priority

    Referenced from: https://wordpress.stackexchange.com/a/331154

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