WordPress.org

Ready to get started?Download WordPress

Codex

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

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

Contents

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 custom columns to a list of custom post types.

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

Parameters

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

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_edit-book_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