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.
// let's say we have a CPT called 'product'
function product_custom_column_values( $column, $post_id ) {
switch ( $column ) {
// in this example, a Product has custom fields called 'product_number' and 'product_name'
case 'product_number' :
case 'product_name' :
echo get_post_meta( $post_id , $column , true );
break;
// in this example, $buyer_id is post ID of another CPT called "buyer"
case 'product_buyer' :
$buyer_id = get_post_meta( $post_id , $column , true );
if( $buyer_id ){
echo get_post_meta( $buyer_id , 'buyer_name' , true );
} else {
echo '<div class="dashicons dashicons-minus"></div>';
}
break;
}
}
add_action( 'manage_product_posts_custom_column' , 'product_custom_column_values', 10, 2 );
For further management of columns, check:
https://developer.wordpress.org/reference/hooks/manage_post_type_posts_columns/
To add/remove/rename columns
https://developer.wordpress.org/reference/hooks/list_table_primary_column/
To set the primary (default) column
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.