Move Across WordPress Draft, Pending And Publish Post Statuses

Don’t use register_post_status before init. Register Post Status is a function used to create and modify post status based on given parameters. register_post_status() function is located in wp-includes/post.php It accepts following two parameters:

  • $post_status means a string for the post status name
  • $args means an array of arguments

<?php register_post_status( $post_status, $args ); ?>

Example:
(Following example registers “Unread” post status:

function my_custom_post_status(){
register_post_status( ‘unread’, array(
‘label’ => _x( ‘Unread’, ‘post’ ),
‘public’ => true,
‘exclude_from_search’ => false,
‘show_in_admin_all_list’ => true,
‘show_in_admin_status_list’ => true,
‘label_count’ => _n_noop( ‘Unread <span class=”count”>(%s)</span>’, ‘Unread <span class=”count”>(%s)</span>’ ),
) );
}
add_action( ‘init’, ‘my_custom_post_status’ );

Where:

  • label is a descriptive name for the post status marked for translation.
  • public – Set true to show posts of this status in the front end. Defaults to false.
  • exclude_from_search – Set true to exclude posts with this post status in search results. Defaults to false.
  • show_in_admin_all_list – Defines whether to include posts in the edit listing for their post type.
  • show_in_admin_status_list – Shows in the list of statuses with post counts. Example: Published (12)
  • label_count – The text to display on admin screen or you won’t see status count.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.