WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Plugin API/Action Reference/manage $post type posts custom column

Description

This action is called whenever a value for a custom column should be output for a custom post type. Combined with the manage_${post_type}_posts_columns filter, this allows you to add or remove (unset) custom columns to a list of custom post types.

For built-in post types and multiple custom types, use manage_posts_custom_column.

Parameters

Posts and Pages

A registered action function is passed the following parameters.

$column_name
(string) (required) The name of the column to display.
Default: None
$post_id
(int) (required) The ID of the current post. Can also be taken from the global $post->ID
Default: None

Terms and Taxonomies

When passing this function on terms and taxonomies, a third parameter is added.

$null
(null) (required) Unused and won't pass anything.
Default: None
$column_name
(string) (required) The name of the column to display.
Default: None
$term_id
(int) (required) The ID of the current term. Can also be taken from the global $current_screen->taxonomy.
Default: None

Examples

Suppose you have a 'book' custom post type and you want to add the publisher and book author in the edit page but remove the post author.

add_filter( 'manage_book_posts_columns', 'set_custom_edit_book_columns' );
add_action( 'manage_book_posts_custom_column' , 'custom_book_column', 10, 2 );

function set_custom_edit_book_columns($columns) {
    unset( $columns['author'] );
    $columns['book_author'] = __( 'Author', 'your_text_domain' );
    $columns['publisher'] = __( 'Publisher', 'your_text_domain' );

    return $columns;
}

function custom_book_column( $column, $post_id ) {
    switch ( $column ) {

        case 'book_author' :
            $terms = get_the_term_list( $post_id , 'book_author' , '' , ',' , '' );
            if ( is_string( $terms ) )
                echo $terms;
            else
                _e( 'Unable to get author(s)', 'your_text_domain' );
            break;

        case 'publisher' :
            echo get_post_meta( $post_id , 'publisher' , true ); 
            break;

    }
}

Change Log

Source File

manage_{$post_type}_posts_custom_column is located in wp-admin/includes/class-wp-posts-list-table.php.

Related

Actions

Filters