Create Custom Post Status

WordPress post status is used to describe the state of the post. Followings are some of built-in post status:

  • Draft: Incomplete posts viewable by anyone with proper user level.
  • Future: Scheduled posts to be published on a future date.
  • Pending: Awaiting approval from another user (editor or higher) to publish.
  • Published: Live posts on your blog that are viewable by everyone.
  • Private: Posts that are viewable only to WordPress users at Administrator level.
  • Trash: Deleted posts sitting in the trash (you can empty the trash to delete them permanently).
  • Auto-Draft: Revisions that WordPress saves automatically while you are editing.

If you want to create your own post status without using plugin, you need to add following code into functions.php of your child theme which add “In Writing” post status on your post:

// Register Custom Post Status
function register_custom_post_status(){
    register_post_status( 'In Writing', array(
        'label'                     => _x( 'In Writing', 'post' ),
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop( 'In Writing <span class="count">(%s)</span>', 'In Writing <span class="count">(%s)</span>' ),
    ) );
}
add_action( 'init', 'register_custom_post_status' );

// Display Custom Post Status Option in Post Edit
function display_custom_post_status_option(){
    global $post;
    $complete = '';
    $label = '';
    if($post->post_type == 'post'){
        if($post->post_status == 'in-writing'){
            $selected = 'selected';
        }
echo '<script>
$(document).ready(function(){
$("select#post_status").append("<option value=\"in-writing\" '.$selected.'>In Writing</option>");
$(".misc-pub-section label").append("<span id=\"post-status-display\"> In Writing</span>");
});
</script>
';
    }
}
add_action('admin_footer', 'display_custom_post_status_option');

You can then see this post status in admin post editing page. That’s it 🙂

Leave a comment