Identifying All Available Post Statuses In WordPress

Overview of Default WordPress Post Statuses

WordPress comes with several default post statuses that you can assign to posts in order to indicate the current state of the post. Understanding these statuses can help manage and organize your site’s content more effectively. The main default post statuses in WordPress are:

Published

The published status means the post is live on your site and visible to site visitors. Published posts are included in feeds, can be syndicated, and are available to search engines. This is the default status when you first create a post in WordPress.

Pending Review

The pending review status allows contributors to submit posts for review by an editor. Posts with this status are not visible publicly. Editors can see pending review posts and choose to publish them or send back for further revisions.

Draft

Posts with draft status are unfinished drafts only visible to the post author in the WordPress admin. Drafts are useful for saving work in progress but keeping posts hidden until they are ready to publish.

Auto-Draft

Auto-draft refers to post drafts that are automatically saved while writing. This allows recovering content in case of loss of connectivity or failure to save properly. Auto-drafts are only visible to post authors.

Future

Future is used to schedule posts to be published at a future date/time. Future posts are not visible to site visitors until their set publish time, allowing dated content to be prepared ahead of time.

Private

Making a post private hides it from the public site. Private posts are only visible to logged in users that have permission to view them. This allows creating posts meant only for site members.

Inherently Private

Some custom post types are defined with an inherently private status. Even if made public, these posts only display to users with appropriate capabilities and never show in the front-end of the site.

Trash

Trashing a post stores it in the trash instead of completely deleting. Trashed posts can then be permanently deleted or restored if needed. This gives you a chance to undo accidental post deletions.

Viewing Available Post Statuses in the Database

To see a full list of post statuses defined in your WordPress database, you can query the wp_posts table directly. This will display all the available statuses that can be assigned to posts:


SELECT DISTINCT post_status 
FROM wp_posts; 

Running this SQL query will output the defined post statuses, including default WordPress statuses as well as any custom ones created by plugins or themes. Some examples of output could be:


+------------------+
| post_status      |
+------------------+
| publish          |
| pending          |
| draft            |  
| auto-draft       |
| future           |
| private          |
| inherit          |
| trash            |
| my_custom_status |
+------------------+

This provides an easy way to see all the available values that can be assigned to the post_status field in the posts table. In addition to the post statuses visible here, some plugins may use custom techniques or external tables to manage statuses.

Modifying or Adding Custom Post Statuses

In addition to the default statuses, WordPress allows registering custom post statuses. This allows you to define additional states that posts can take on. Some common reasons to add custom statuses include:

  • Adding editorial workflow states – For example, “In Review” or “Awaiting Revision”
  • Indicating access levels – Like “Members Only” for private community posts
  • Marking post conditions – Such as “Outdated” or “Featured”
  • Creating categories for custom post types – For instance “For Sale” or “Expired” for listings

Using register_post_status()

WordPress includes the register_post_status() function for defining custom post statuses. To add a new status, you call this function with an array of status arguments:

 
register_post_status( $status, $args );

Some of the arguments you can define include:

  • label – Descriptive name for the status visible to users
  • public – Whether posts with this status should be shown in feeds or archives
  • exclude_from_search – Exclude posts from front-end search results
  • show_in_admin_* – Display status in various admin UI areas
  • label_count – Text with post count for admin status lists

Example adding a “In Review” status

Here is sample code to register a new “In Review” status using the register_post_status() function:


function add_in_review_status() {

  register_post_status('in_review', array(
    'label' => _x( 'In Review', 'post' ),
    'public' => true,
    'exclude_from_search' => false,
    'show_in_admin_all_list' => true,
    'show_in_admin_status_list' => true,
    'label_count' => _n_noop( 'In Review (%s)', 'In Review(%s)' )
  ));

}

add_action( 'init', 'add_in_review_status' );  

This would add an “In Review” status usable in posts and other relevant admin post lists/counts.

Setting Post Status via Code

Manually editing posts to change status can be time consuming. WordPress includes API functions to programmatically modify post statuses in code:

Using wp_update_post()

The wp_update_post() function allows updating multiple post fields at once, including status. For example, to set a post’s status to “In Review” defined above:


$my_post = array(
  'ID'           => 123,
  'post_status'   => 'in_review',  
);

wp_update_post( $my_post );  

Where you pass an array with the post ID and new status value. Additional fields like post_title, post_content, etc could also be updated via wp_update_post().

Some other functions that can modify post status include:

  • wp_publish_post() – Publish post
  • wp_trash_post() – Move post to trash
  • wp_delete_post() – Delete post

Using these functions allows programmatic post status automation based on any conditions needed. For example, automatically approving posts once reviewed, expiring event posts after the event date passes, etc.

Conclusion

Understanding the post statuses in WordPress unlocks more control over managing your site’s content. The default statuses like draft and pending provide basic editorial workflow. Custom statuses expand this with additional states like highlighting featured content, marking groups of posts, setting access levels, and more.

The register_post_status() function enables declaring any new statuses required. And status-modifying functions like wp_update_post() allow easily changing statuses in code. Combining these capabilities enables automating post state based on complex conditions to handle numerous use cases.

So properly utilizing all the available post statuses provides more organizational control. This keeps content orderly as sites grow in size and complexity over time.

Leave a Reply

Your email address will not be published. Required fields are marked *