This article will show you how to create custom post status and add that post status to the WordPress post status drop down menu.
Registering WordPress custom post status ‘archive’
To create a custom post status in wordpress, you need to first register it in your wordpress theme, once registered at first you will not notice anything different. Once you have added a post to your new status you will notice in the administration index for that post type will display a new link to view all posts with your new status.Add the snippet below to your themes functions.php file.
<?php function jc_custom_post_status(){ register_post_status( 'archive', array( 'label' => _x( 'Archive', 'post' ), 'public' => true, 'show_in_admin_all_list' => false, 'show_in_admin_status_list' => true, 'label_count' => _n_noop( 'Archive <span class="count">(%s)</span>', 'Archive <span class="count">(%s)</span>' ) ) ); } add_action( 'init', 'jc_custom_post_status' ); ?> |
Adding custom post status to WordPress status dropdown
WordPress custom post statuses can be used without adding them to the edit posts post status drop down menu, but for this demonstration it is a good visual starting point.Add the following snippet in your themes functions.php file.
add_action('admin_footer-post.php', 'jc_append_post_status_list'); function jc_append_post_status_list(){ global $post; $complete = ''; $label = ''; if($post->post_type == 'post'){ if($post->post_status == 'archive'){ $complete = ' selected=\"selected\"'; $label = '<span id=\"post-status-display\"> Archived</span>'; } echo ' <script> jQuery(document).ready(function($){ $("select#post_status").append("<option value=\"archive\" '.$complete.'>Archive</option>"); $(".misc-pub-section label").append("'.$label.'"); }); </script> '; } } |
if($post->post_type == 'posts'){ |
Click on the blue button to update the post, now in the administration index page for this post type you should have a new archive filter to display posts with your custom post status, shown below:
Adding custom post status to post type index
To finish your new custom post status by making it easier to tell the difference between your new status and others, for example when you make a post private in the list of posts you get a private next to the post.Add the following snippet to your functions.php file to add this to your custom post status:
function jc_display_archive_state( $states ) { global $post; $arg = get_query_var( 'post_status' ); if($arg != 'archive'){ if($post->post_status == 'archive'){ return array('Archive'); } } return $states; } add_filter( 'display_post_states', 'jc_display_archive_state' ); |
$arg = get_query_var( 'post_status' ); if($arg != 'archive'){ // code here if archive post status not selected }


ReplyDeleteHello,
we provide affordable and result-oriented SEO services, please give a chance to serve you.
Thanks
Admin: E07.net