Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've done this with posts, but I can't find the proper way to reference the category table's columns.

I'm trying to add a column titled "Image" to the table, so that when the table grid of categories is displayed, if there is a category image assigned to the category, it will appear in the grid.

The first step for me is to determine the proper filter to address in order to insert the columb into the table.

I've tried each of these to no avail...

add_filter('manage_categories_columns', 'myFunction', 10, 2);
add_filter('manage_category_columns', 'myFunction', 10, 2);

function myFunction($cat_columns)
{
    $cat_columns['cat_image_thumb'] = 'Image';
    return $cat_columns;
}
share|improve this question
add comment

3 Answers

up vote 3 down vote accepted

The filter is manage_{$screen->id}_columns, and $screen->id is edit-category, giving you manage_edit-category_columns.

I found this by placing a var_dump() in get_column_headers(), which is called by print_column_headers(), which is called in wp-admin/edit-tags.php, the page where you edit the category items.

share|improve this answer
    
@Jan: Thanks! That did it for the column header. Now I'm trying to use your trace route to find out how to add the row insert. Looking into edit-tags.php I see the "tag_rows" call, which I believe is what creates the rows, but I can't locate that function in order to var_dump to get the filter name. Any ideas? –  Scott B Jan 13 '11 at 15:02
    
@Scott: If you're talking about a hierarchical taxonomy like categories, tag_rows() calls _term_rows(), which calls _tag_row(). This function calls the manage_{$taxonomy}_custom_column action, which would be manage_category_custom_column for you. –  Jan Fabry Jan 13 '11 at 15:10
    
@Jan thanks. I'm able to set the action, but can't seem to get the echo to respond.. action > add_action('manage_category_custom_column', 'myFunction', 10, 2); –  Scott B Jan 13 '11 at 15:27
    
@Scott: Indeed, I was wrong, it is a filter, not an action, so you should return the content you want to display, not echo it - in contrast to post custom columns, where you have to echo it. –  Jan Fabry Jan 13 '11 at 15:35
    
OK, that's better. Works perfectly with filter and return vs action and echo. Thanks Jan! –  Scott B Jan 13 '11 at 15:37
show 5 more comments

Adding the column name

function manage_my_category_columns($columns)
{
 // add 'My Column'
 $columns['my_column'] = 'My Column';

 return $columns;
}
add_filter('manage_edit-category_columns','manage_my_category_columns');

Next we want to put the data in it:

function manage_category_custom_fields($deprecated,$column_name,$term_id)
{
 if ($column_name == 'my_column') {
   echo 'test';
 }
}
add_filter ('manage_category_custom_column', 'manage_category_custom_fields', 10,3);

I hope this was useful.

share|improve this answer
add comment

In addition to @LeoDang's example, the custom_column is applied to custom taxonomy based on the following filters.

Tested and validated in Wordpress 3.8

1.Adding custom column header

//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.Adding Custom Column Data to corresponding Column Header

//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 === 'header_name') {
        // echo '1234';
    // }
    // return $columns;
}
add_action( "manage_shop-subcategory_custom_column", 'custom_column_content', 10, 3);

You may also refer to the gist code shared online for any update and additional notes.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.