public
Last active

Adding custom column displaying in Wordpress Manage Category/Custom Taxonomy editing page

  • Download Gist
add_custom_column_to_edit_tag.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
/*
Purpose: add custom column header and custom column content to respective custom header in Manage Category Editing Page
Version Tested: 3.8
Story:
Because I found no explanation nor documents in Wordpress.org, I tried to trace the code in wp-admin folder
after understanding the operation of apply_filter(), add_action() and add_filter()
Logic:
The table list in edit_tag.php is based on
wp-admin/includes/class-wp-list-table.php and
wp-admin/includes/class-wp-terms-list-table.php
Note: actually class-wp-terms-list-table.php is creating a class extend the basic table list class in class-wp-list-table.php
Reference:
http://wordpress.stackexchange.com/questions/6883/how-can-i-add-a-custom-column-to-the-manage-categories-table/129545#129545
*/
//Example
 
//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['order_unit'] = 'Order Unit';
return $columns;
}
add_filter( "manage_edit-shop-subcategory_columns", 'custom_column_header', 10);
 
 
//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
// if ($column_name === 'order_unit') {
// echo '1234';
// }
// return $columns;
}
add_action( "manage_shop-subcategory_custom_column", 'custom_column_content', 10, 3);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.