I think what you need is the set of filters and actions to add custom columns to post edit screens:
- manage_edit-post_type_columns: used to add columns
- manage_posts_custom_column: used to print the content of each row of the column
- manage_edit-post_type_sortable_columns: used to register sortable columns. Undocumented.
- request: you may need to use this filter in combination with
manage_edit-post_type_sortable_columns
.
For example, I use this code to add a sortable column with post hits information from a custom meta field:
add_filter( 'manage_edit-post_columns', 'add_new_columns' );
add_filter( 'manage_edit-post_sortable_columns', 'register_sortable_columns' );
add_filter( 'request', 'hits_column_orderby' );
add_action( 'manage_posts_custom_column' , 'custom_columns' );
/**
* Add new columns to the post table
*
* @param Array $columns - Current columns on the list post
*/
function add_new_columns($columns){
$column_meta = array( 'hits' => 'Hits' );
$columns = array_slice( $columns, 0, 6, true ) + $column_meta + array_slice( $columns, 6, NULL, true );
return $columns;
}
// Register the columns as sortable
function register_sortable_columns( $columns ) {
$columns['hits'] = 'hits';
return $columns;
}
//Add filter to the request to make the hits sorting process numeric, not string
function hits_column_orderby( $vars ) {
if ( isset( $vars['orderby'] ) && 'hits' == $vars['orderby'] ) {
$vars = array_merge( $vars, array(
'meta_key' => 'hits',
'orderby' => 'meta_value_num'
) );
}
return $vars;
}
/**
* Display data in new columns
*
* @param $column Current column
*
* @return Data for the column
*/
function custom_columns($column) {
global $post;
switch ( $column ) {
case 'hits':
$hits = get_post_meta( $post->ID, 'hits', true );
echo (int)$hits;
break;
}
}