Adding custom post statuses in WordPress can be useful when you want to add a new status to your posts or custom post types, such as “Pending Review” or “Approved”.
Please note: At the time of writing (September 2023), it is possible to register a post status so it can be used as a value for the ‘post_status’ field. You can use the custom post status when querying posts (using WP_Query
or get_posts()
for example. However, the post status will not show up in the admin panel as a custom status you can pick. This is due to a long standing “bug”, see the issue on Trac.
Here’s how you can add a custom post status:
function wpsnippets_custom_post_status() {
register_post_status('custom_status', array(
'label' => 'Custom Status',
'public' => true,
'exclude_from_search' => true,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop('Custom Status <span class="count">(%s)</span>', 'Custom Status <span class="count">(%s)</span>')
));
}
add_action('init', 'wpsnippets_custom_post_status');
This code registers a custom post status called “Custom Status” with the register_post_status()
function. You can customize the label, visibility, and other properties of the custom post status by modifying the arguments passed to the register_post_status()
function.
If you want to add a custom post status called “Pending Review”, you can replace the arguments with the following:
register_post_status('pending_review', array(
'label' => 'Pending Review',
'public' => true,
'exclude_from_search' => true,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop('Pending Review <span class="count">(%s)</span>', 'Pending Review <span class="count">(%s)</span>')
));
This code registers a custom post status called “Pending Review” with the same visibility and label properties as the previous example.
That’s it! Remember, when you edit a post or custom post type, you will not see your custom post status in the “Status” dropdown menu (at least at the time of writing, see note at the top of this post). You can however filter your posts or custom post types by your custom post status in the admin area.
Note: Custom post statuses will be registered globally and are not tied to a specific post type. The custom registered status will be available for all registered post types.