Wordpress - Custom columns on edit-tags.php main page
You can do this by hooking into the 'taxonomy'_edit_form and edited_'taxonomy' actions.
add_action('taxonomy_edit_form', 'foo_render_extra_fields');
function foo_render_extra_fields(){
$term_id = $_GET['tag_ID'];
$term = get_term_by('id', $term_id, 'taxonomy');
$meta = get_option("taxonomy_{$term_id}");
//Insert HTML and form elements here
}
add_action('edited_taxonomy', 'bar_save_extra_fields', 10, 2);
function bar_save_extra_fields($term_id){
$form_field_1 = $_REQUEST['field-name-1'];
$form_field_2 = $_REQUEST['field-name-2'];
$meta['key_value_1'] = $form_field_1;
$meta['key_value_2'] = $form_field_2;
update_option("taxonomy_{$term_id}", $meta);
}
Make sure to change 'taxonomy' throughout the code example with your custom taxonomy. Be advised, this will only display on when a user edits a tag or category.
Update to add columns to the edit tags table:
function add_post_tag_columns($columns){
$columns['foo'] = 'Foo';
return $columns;
}
add_filter('manage_edit-post_tag_columns', 'add_post_tag_columns');
function add_post_tag_column_content($content){
$content .= 'Bar';
return $content;
}
add_filter('manage_post_tag_custom_column', 'add_post_tag_column_content');
This works like a charm! Here's a screenshot: http://3-3.me/lFdf
Just for posterity, because I, like @IV4 still had a bit of wrangling to do with @Brian's answer to get it to work for a custom tax:
add_filter( "manage_{screen_id}_columns", "column_header_function" ) );
add_action( "manage_{tax_slug}_custom_column", "populate_rows_function"), 10, 3 );
So in my case, my custom taxonomy was "product-category", so it looked like this for me:
add_filter( "manage_edit-product-category_columns", array ( __CLASS__, "populate_edit_page_column_header" ) );
add_action( "manage_product-category_custom_column", array ( __CLASS__, "populate_edit_page_columns"), 10, 3 );
It should also be noted (though veterans will already know this) that for a taxonomy custom column you can ONLY create custom row data for columns that are not defined by default. The reason for this is that within the WP_Terms_List_Table
class, unlike the way the WP_Posts_List_Table
class works, the custom column action is only called through the column_default
method, which is only invoked if the column name does not match one of the default columns defined in that class (cb, description, links, name, posts, slug).
In my case I wanted to modify the description column, but had to resort to creating a custom column called 'summary' instead. Also note that custom columns would have to be added to the sort filter if you wanted to sort on that column (though sorting on a description column didn't make sense in my case).
In terms of the action's function signature, it can take up to 3 arguments, the first of which is actually useless (which makes me wonder how @Brian's answer worked at all):
function my_custom_columns( $value, $column, $term_id ){ }
Where $value
is basically empty, $column
is what you want to switch on and $term_id
could be very important if you need to reference any data contained in your term!