How to add a custom post status in wordpress for custom post type or post post type
For add a new custom post status add below code in your theme's function.php or your custom plugin's file
<?php
For Display custom status on dropdown while add or edit post
<?php
add_action('admin_footer-post.php', 'rj_append_post_status_list',9999);
function rj_append_post_status_list(){
global $post;
$complete = '';
$label = '';
if($post->post_status == 'hide'){
$complete = ' selected="selected"';
$label = '<span id="post-status-display"> Hide</span>';
}
echo '
<script>
jQuery(document).ready(function($){
$("select#post_status").append("<option value=\"hide\" '.$complete.'>Hide</option>");
$(".misc-pub-section label").append("'.$label.'");
});
</script>
';
}
?>
For display custom status on quick edit post
function rj_append_post_status_bulk_edit() {
global $post;
if($post->post_status == 'hide'){
$complete = ' selected="selected"';
}
echo '
<script>
jQuery(document).ready(function($){
$(".inline-edit-status select ").append("<option value="\"hide\"" '.$complete.' >Hide</option>");
});
</script>
';
}
add_action( 'admin_footer-edit.php', 'rj_append_post_status_bulk_edit' );
<?php
function rj_custom_post_status(){ register_post_status( 'hide', array( // hide => change with your custom status slug 'label' => _x( 'Hide', 'post' ), // Hide -> change with ur status name 'public' => true,
'exclude_from_search' =>false,
'show_in_admin_all_list' => false, 'show_in_admin_status_list' => true, 'label_count' => _n_noop( 'Hide<span class="count">(%s)</span>', 'Hide<span class="count">(%s)</span>' ) ) ); } add_action( 'init', 'rj_custom_post_status',10 ); ?>
For Display custom status on dropdown while add or edit post
<?php
add_action('admin_footer-post.php', 'rj_append_post_status_list',9999);
function rj_append_post_status_list(){
global $post;
$complete = '';
$label = '';
if($post->post_status == 'hide'){
$complete = ' selected="selected"';
$label = '<span id="post-status-display"> Hide</span>';
}
echo '
<script>
jQuery(document).ready(function($){
$("select#post_status").append("<option value=\"hide\" '.$complete.'>Hide</option>");
$(".misc-pub-section label").append("'.$label.'");
});
</script>
';
}
?>
For display custom status on quick edit post
function rj_append_post_status_bulk_edit() {
global $post;
if($post->post_status == 'hide'){
$complete = ' selected="selected"';
}
echo '
<script>
jQuery(document).ready(function($){
$(".inline-edit-status select ").append("<option value="\"hide\"" '.$complete.' >Hide</option>");
});
</script>
';
}
add_action( 'admin_footer-edit.php', 'rj_append_post_status_bulk_edit' );
Comments
Post a Comment