Add custom column at custom posts list

Adding A New Column To The books Post Table

Here we can use the filters

manage_{$post->post_type}_posts_custom_column
manage_{$post->post_type}_posts_columns

or for the books post type:

manage_books_posts_custom_column
manage_books_posts_columns

Here’s an example how we could display a button, for each row in the send_email column:

/**
 * Books Post Table: Display a utton in each row in the 'send_email' column
 */
add_action( 'manage_books_posts_custom_column', function ( $column_name, $post_id ) 
{
    if ( $column_name == 'send_email')
        printf( '<input type="button" value="%s" />', esc_attr( __( 'Send Email' ) ) );

}, 10, 2 );

To add the send_email column we can use:

/**
 * Books Post Table: Add the 'send_email' column
 */
add_filter('manage_books_posts_columns', function ( $columns ) 
{
    if( is_array( $columns ) && ! isset( $columns['send_email'] ) )
        $columns['send_email'] = __( 'Send Email' );     
    return $columns;
} );

We could also limit the column width with:

/**
 * Limit the 'send_email' column width
 */
add_action( 'admin_print_styles-edit.php', function()
{        
    echo '<style> .column-send_email { width: 100px; }</style>';
} );

Here’s an example output:

button

You will then have to implement how the button will work.

ps: I removed the second part from my answer, since that part of your question, would be better served as a new separate question.

Leave a Comment