Custom columns on edit-tags.php main page

I am trying to add custom columns to edit-tags.php for a custom taxonomy that I have created. This custom taxonomy is called equipment-types and it only applies to one custom post type called equipment. I am trying to use the same filters and actions that I would use to add custom columns on the edit.php page. I was able to actually create the custom columns with this filter:

add_filter('manage_edit-equipment-types_columns', 'define_equip_types_columns');

However, I cannot seem to populate these columns with any data. Normally, for the edit.php page I would use the following action:

Read More
add_action('manage_posts_custom_column', 'my_post_type_columns_content'));

And then within the my_post_type_columns_content function I would conditionally output column data based on the post-type.

The problem is I can’t seem to find a similar hook for the edit-tags page. Adam Brown’s website lists these hooks:

manage_blogs_custom_column

manage_comments_custom_column

manage_comments_nav

manage_link_custom_column

manage_media_custom_column

manage_media_media_column

manage_pages_custom_column

manage_plugins_custom_column

manage_posts_custom_column

manage_sites_custom_column

manage_themes_custom_column

manage_{$post->post_type}_posts_custom_column

None of which I think would be any help. Does anyone know of a way to do this? I’m so close, I have the columns created with titles, I just need to fill them with data!

EDIT: To be clear, I am not trying to make custom fields. I am trying to make custom COLUMNS in the table to the right on the main taxonomy page.

Regularly on the edit.php page where it displays All Posts for that post type I can make custom columns such as the quantity column like this:

enter image description here

However, I don’t think there is a hook to populate the columns on the edit-tags.php main page, even though I can create a custom column such as Image URL below:

enter image description here

Related posts

Leave a Reply

3 comments

  1. 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

  2. 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!

  3. For adding on the main screen:

    add_action( '<taxonomy-name>_add_form_fields', 'addfields' );
    function addfields() {
        echo "<div class='form-field'><label>Wassup</label><textarea></textarea></div>";
    }
    

    For adding on individual term edit form:

    add_action( '<taxonomy-name>_edit_form_fields', 'editfields' );
    function editfields() {
        echo "<tr class='form-field'><th>Wassup</th><td><textarea></textarea></td></tr>";
    }
    

    I’ve tested this, it works. See the screens:

    taxo_add_form_fields,taxo_edit_form_fields.

    Replace <taxonomy name> with ‘category’ if you want this on the regular post categories. For saving the values wherever you want, you will need:

    add_action( 'created_term',  'store_my_field' , '', 3 );
    add_action( 'edit_term',  'store_my_field' , '', 3 );