Skip to content

Instantly share code, notes, and snippets.

@simongcc
Last active March 30, 2021 06:39
Show Gist options
  • Select an option

  • Save simongcc/8395576 to your computer and use it in GitHub Desktop.

Select an option

Save simongcc/8395576 to your computer and use it in GitHub Desktop.

Revisions

  1. simongcc revised this gist Apr 8, 2020. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions add_custom_column_to_edit_tag.php
    Original file line number Diff line number Diff line change
    @@ -15,10 +15,10 @@
    Reference:
    http://wordpress.stackexchange.com/questions/6883/how-can-i-add-a-custom-column-to-the-manage-categories-table/129545#129545
    */
    //Example
    // Example

    //these filters will only affect custom column, the default column will not be affected
    //filter: manage_edit-{$taxonomy}_columns
    // 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;
    @@ -33,7 +33,7 @@ function custom_column_content( $value, $column_name, $tax_id ){
    // var_dump( $value );
    // var_dump( $tax_id );

    //for multiple custom column, you may consider using the column name to distinguish
    // 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') {
  2. simongcc revised this gist Apr 8, 2020. 1 changed file with 29 additions and 11 deletions.
    40 changes: 29 additions & 11 deletions add_custom_column_to_edit_tag.php
    Original file line number Diff line number Diff line change
    @@ -26,17 +26,35 @@ function custom_column_header( $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
    // 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;
    // 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);
  3. simongcc revised this gist Jan 13, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion add_custom_column_to_edit_tag.php
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@
    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

  4. simongcc created this gist Jan 13, 2014.
    42 changes: 42 additions & 0 deletions add_custom_column_to_edit_tag.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,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:
    */
    //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);