Get a list of ALL Statuses both registered and built-in

This largely depends on where within the boot/request sequence you decide to make an attempt at retrieving statuses and it also depends on whether someone, thing, plugin or theme is doing something, funky, or not but the latter is less likely the case.

Useful API functions:

get_post_statuses docs | source

  • Retrieves statuses for the built in post type of post
    get_available_post_statuses

get_available_post_statuses docs | source

  • Retrieves statuses for the specific post type, but defaults to post if no value is supplied.

get_post_stati docs| source | RECOMMENDED

  • Retrieve statuses, which by default will retrieve all, including built-ins. This function wraps around global $wp_post_statuses; therefore it is recommended that you use that function in place of a direct call to $wp_post_statuses.

If you are calling the global $wp_post_statuses, pay attention to where you are calling it and when within a action or filter, whether the hook fires before or after the point where a statuses is registered and or if within the same hook, whether your priority is before or after registration.

Imagine the following:

Register a type:

add_action('init', function () {
    register_post_status('custom_status', array(
        'label'  => _x('My Status', 'post'),
        'public' => true,
        // shortened for brevity
    ));
}, 20);

Retrieve types:

add_action('init', function () {
    global $wp_post_statuses;
    var_dump( $wp_post_statuses );

    # result... no 'custom_status'
    /*
    array(
        "publish",
        "future",
        "draft",
        "pending",
        "private",
        "trash",
        "auto-draft",
        "inherit",
    )
     */


}, 10);

Retrieve types:

specifying a priority equal to or later than the priority used to register the status:

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

Alternatively if you can use a different hook, one that fires later, for example if someone is registering a status on init and you could alternatively hook into wp_loaded to run your logic which at that point would contain the statuses you need and so on.

Find where the status is being registered and go from there. If you are using a good IDE or similar, you can search the entire code base, both core and vendor (plugins, themes) to find the particular statuses you are trying to track down quite easily. For example PHPStorm has an excellent Find In Path tool to help you with just that. Most other tools would have something similar.

Some helpful material on the loading sequence of WordPress:

Is there a flowchart for WordPress loading sequence?

How to get WordPress’ hooks/actions run sequence?

Leave a Comment