My custom post name is “employee”.
Here is the code for creating and populating admin columns.
Columns have been created but it is not populating. Also, what is the meaning of the “10, 2” in action hook? N.B. location and age values come from custom meta boxes.
add_filter( 'manage_employee_posts_columns', 'set_custom_edit_employee_columns' );
add_action( 'manage_employee_posts_custom_column' , 'custom_employee_column', 10, 2 );
function set_custom_edit_employee_columns($columns) {
unset( $columns['location'] );
$columns['location'] = __( 'Location', 'tm_cp' );
$columns['age'] = __( 'Age', 'tm_cp' );
return $columns;
}
function custom_employee_column( $column, $post_id ) {
switch ( $column ) {
case 'location' :
echo get_post_meta( $post_id , 'location' , true );
break;
case 'age' :
echo get_post_meta( $post_id , 'age' , true );
break;
}
}