how can I add an extra admin column with the Status of posts like Below Image. i know admin column plugin for this work but i don't want to use any plugin..so please suggest me if there any code to add an extra admin column with the Post Status
2 Answers
The last function doesn't work. Use this instead to fill the status column:
// Add the data to the post columns:
add_action( 'manage_post_posts_custom_column' , 'custom_post_column', 10, 2 );
function custom_post_column( $column, $post_id ) {
if ( $column == "status" ) {
echo get_post_status($post_id);
}
}
This is the simplest use of adding custom columns:
// Add the custom columns to the post type:
add_filter( 'manage_post_posts_columns', 'set_custom_edit_book_columns' );
function set_custom_edit_book_columns($columns) {
$columns['status'] = __( 'Status', 'your_text_domain' ); // or simply "Status";
return $columns;
}
// Add the data to the post columns:
add_action( 'manage_post_posts_custom_column' , 'custom_post_column', 10, 2 );
function custom_post_column( $column, $post_id ) {
if ( $column == "status" ) {
$p_status = get_post_meta($post->ID, 'status', true);
echo $p_publish;
}
}
Of course you could also do this column sortable and so on! Not tested, but it should work, you've got the point
You could also check these links, discribing almost the same question as yours:
Add custom columns: http://www.deluxeblogtips.com/add-custom-column/
Add sortable columns: https://wordpress.org/support/topic/admin-column-sorting/
-
This Code is worked to add status Column at my post page but post Status is not showing is Status Column. Commented Aug 1, 2021 at 6:35