Skip to content

Instantly share code, notes, and snippets.

@ruman
Created November 3, 2018 07:29
Show Gist options
  • Save ruman/d40000e9c74737c567738dc2d591bff1 to your computer and use it in GitHub Desktop.
Save ruman/d40000e9c74737c567738dc2d591bff1 to your computer and use it in GitHub Desktop.
Custom Post Status
// Registering custom post status
function wpb_custom_post_status(){
register_post_status('inactive', array(
'label' => _x(
'Inactive', 'post' ),
'public' => false,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>' ),
) );
}
add_action( 'init', 'wpb_custom_post_status' );
// Using jQuery to add it to post status dropdown
add_action('admin_footer-post.php', 'wpb_append_post_status_list');
function wpb_append_post_status_list(){
global $post;
$complete = '';
$label = '';
if($post->post_type == 'post'){
if($post->post_status == 'inactive'){
$complete = ' selected="selected"';
$label = '<span id="post-status-display"> Inactive</span>';
}
echo '
<script>
jQuery(document).ready(function($){
$("select#post_status").append("<option value=\"inactive\" '.$complete.'>Inactive</option>");
$(".misc-pub-section label").append("'.$label.'");
});
</script>
';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment