get_post_statuses()
Retrieve all of the WordPress supported post statuses.
Posts have a limited set of valid status values, this provides the post_status values and descriptions.
No Hooks.
Return
String[]
. Array of post status labels keyed by their status.
Usage
get_post_statuses();
Examples
#1 Get all registered post statuses
$statuses = get_post_statuses(); /* $statuses will contain such an array: Array ( [draft] => Draft [pending] => On approval [private] => Personal [publish] => Published ) */
#2 Get all statuses including custom ones
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 );
Referenced from: https://wordpress.stackexchange.com/a/331154
#3 Hard-coded list WARNING
Note that this function returns a hard-coded list of statuses. 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().
Changelog
Since 2.5.0 | Introduced. |
get_post_statuses() get post statuses code WP 6.1.1
function get_post_statuses() { $status = array( 'draft' => __( 'Draft' ), 'pending' => __( 'Pending Review' ), 'private' => __( 'Private' ), 'publish' => __( 'Published' ), ); return $status; }