为自定义帖子类型创建自定义列及其关联数据的挂钩分别是manage{$post\\u type}\\u posts\\u columns和manage{$post\\u type}\\u posts\\u custom\\u column,其中{$post\\u type}是自定义帖子类型的名称。
文档中的此示例删除了作者列,并添加了分类法和元数据列:
// Add the custom columns to the book post type:
add_filter( \'manage_book_posts_columns\', \'set_custom_edit_book_columns\' );
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;
}
// Add the data to the custom columns for the book post type:
add_action( \'manage_book_posts_custom_column\' , \'custom_book_column\', 10, 2 );
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;
}
}
从现有ans复制。