8

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:

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

1
  • 1
    you mention in a comment that you got this to work. Would you mind updating this post, or better, providing another answer that lists how you do this for a custom taxonomy? Do it for the children.
    – Tom Auger
    Sep 29, 2011 at 3:20

3 Answers 3

8

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

7
  • Sorry, maybe I wasn't clear, this is not what I'm looking for. I know how to make custom fields for a taxonomy. I'm not trying to make custom fields. I'm trying to make custom COLUMNS in the table that is displayed on the edit-tags main page. There is a section to the left where you can add a new tag and then a section to the right with a table. I am trying to add custom columns to that table just as you would on the edit.php page for All Posts.
    – IV4
    Sep 14, 2011 at 6:28
  • I understood you completely. My code does exactly what you are asking for, but only on the taxonomy term edit form. It's a bit wonky to add the fields to the main add taxonomy form. I created an ad management plugin and had a custom taxonomy for adzones. I added fields to the taxonomy so I could give the user more options for their adzones. The fields again did not display on the main screen, only when the user edited a specific term. Sep 14, 2011 at 6:51
  • I'm NOT talking about fields. There is no update_option involved. I already know how to do all of that stuff. I'll try to update my question with pics so you know what I'm talking about.
    – IV4
    Sep 14, 2011 at 17:07
  • Also, to add fields to the main screen you can use the taxonomy_add_form_fields hook to place the fields within the default form or taxonomy_add_form to make a new form. To save these fields you can use the created_taxonomy hook.
    – IV4
    Sep 14, 2011 at 17:11
  • Sorry I misunderstood. I'll dig through the source to see what I come up with. :) Sep 14, 2011 at 17:26
4

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!

0

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 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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