register_post_status

Home » Functions » register_post_status

Function Name: register_post_status

WordPress has a built-in system for post statuses that allows users to define the state of a post, such as "published," "draft," or "pending." However, sometimes these default post statuses don’t quite fit the needs of a particular website or application. This is where the register_post_status() function comes in.

The register_post_status() function allows developers to register their own custom post statuses, which can be used to categorize posts in unique ways. These custom post statuses can be used in much the same way as the default post statuses, but can provide additional functionality or organization for certain types of content.

Here’s an example of how to use the register_post_status() function:

function wpse_custom_post_status() {
   register_post_status( 'wc-completed', array(
      'label'                     => _x( 'Completed', 'Order status', 'text_domain' ),
      'public'                    => true,
      'exclude_from_search'       => false,
      'show_in_admin_all_list'    => true,
      'show_in_admin_status_list' => true,
      'label_count'               => _n_noop( 'Completed (%s)', 'Completed (%s)', 'text_domain' )
   ) );
}
add_action( 'init', 'wpse_custom_post_status' );

In this example, we’re registering a custom post status called "wc-completed," which is intended for use with an e-commerce store. The label parameter defines how the custom post status will be displayed in the WordPress admin interface, and the other parameters control things like whether the post status should be searchable, and whether it should be shown in certain parts of the admin interface.

Overall, the register_post_status() function is a powerful and flexible tool for WordPress developers who need to create custom post statuses for their websites or applications.

Learn More on WordPress.org

Register an account to save your snippets or go Pro to get more features.