WordPress allows developers to create custom post statuses beyond the default ones like Published, Draft, Pending, etc. This is useful for adding statuses that are specific to your site or plugin. For example, an ecommerce site may want statuses like "Awaiting Payment", "Payment Received", "Shipped", etc.
To register a custom status, you use the register_post_status() function. This function allows you to specify details about the status such as the label, whether it publicly queryable, etc.
Here is an example registration:
register_post_status( 'awaiting_payment', array(
'label' => _x( 'Awaiting Payment', 'post status', 'textdomain' ),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Awaiting Payment <span class="count">(%s)</span>', 'Awaiting Payment <span class="count">(%s)</span>' )
) );
Some key arguments here:
Once registered, you would use this status when inserting or updating posts. For example:
$post_id = wp_insert_post(array(
'post_status' => 'awaiting_payment',
// other post data
));
Some key advantages of custom statuses:
The registration process takes just a bit of code but then is easy to leverage globally. Definitely a useful tool for developers and advanced sites!