Ngoài ví dụ của @ LeoDang, custom_column được áp dụng cho phân loại tùy chỉnh dựa trên các bộ lọc sau.
Đã kiểm tra và xác nhận trong Wordpress 3.8
1. Thêm tiêu đề Cột tùy chỉnh
// these filters will only affect custom column, the default column will not be affected
// filter: manage_edit-{$taxonomy}_columns
function custom_column_header( $columns ){
$columns['header_name'] = 'Header Name for Display';
return $columns;
}
add_filter( "manage_edit-shop-subcategory_columns", 'custom_column_header', 10);
2. Thêm dữ liệu cột tùy chỉnh vào tiêu đề cột tương ứng
// parm order: value_to_display, $column_name, $tag->term_id
// filter: manage_{$taxonomy}_custom_column
function custom_column_content( $value, $column_name, $tax_id ){
// var_dump( $column_name );
// var_dump( $value );
// var_dump( $tax_id );
// for multiple custom column, you may consider using the column name to distinguish
// although If clause is working, Switch is a more generic and well structured approach for multiple columns
// if ($column_name === 'header_name') {
// echo '1234';
// }
switch( $column_name ) {
case 'header_name1':
// your code here
$value = 'header name 1';
break;
case 'header_name2':
// your code here
$value = 'header name 2';
break;
// ... similarly for more columns
default:
break;
}
return $value; // this is the display value
}
add_action( "manage_shop-subcategory_custom_column", 'custom_column_content', 10, 3);
Bạn cũng có thể tham khảo mã chính được chia sẻ trực tuyến cho bất kỳ cập nhật và ghi chú bổ sung.