Here’s a way to add an extra Comment Status field to the posts list table:
add_filter('manage_post_posts_columns', function ( $columns )
{
$_columns = [];
foreach( (array) $columns as $key => $label )
{
$_columns[$key] = $label;
if( 'title' === $key )
$_columns['wpse_comment_status'] = esc_html__( 'Comment Status', 'mydomain' );
}
return $_columns;
} );
add_action( 'manage_post_posts_custom_column', function ( $column_name, $post_id )
{
if ( $column_name == 'wpse_comment_status')
echo get_post_field( 'comment_status', $post_id );
}, 10, 2 );
Here’s how we can add a support for comment status ordering through the posts_orderby
filter:
add_filter( 'manage_edit-post_sortable_columns', function ( $columns )
{
$columns['wpse_comment_status'] = 'comment_status';
return $columns;
} );
add_filter( 'posts_orderby', function( $orderby, \WP_Query $q ) use ( &$wpdb )
{
$_orderby = $q->get( 'orderby' );
$_order = $q->get( 'order' );
if(
is_admin()
&& $q->is_main_query()
&& did_action( 'load-edit.php' )
&& 'comment_status' === $_orderby
)
$orderby = " {$wpdb->posts}.comment_status "
. ( 'ASC' === strtoupper( $_order ) ? 'ASC' : 'DESC' )
. ", {$wpdb->posts}.ID DESC ";
return $orderby;
}, 10, 2 );
where we sub-order by the post ID.
Here’s an example output:
PS: Since WordPress 4.5 (#35601) it’s possible to filter WP_Query
by comment_status
and ping_status
, so you should be able to implement such filtering for your the posts list table, as well