Display Custom Column in CPT Taxonomy

I am trying to add a column to one of my custom post types, but only on the edit taxonomy page.

I have a taxonomy registered called "event-categories" for my custom post type "events".

I can successfully add the custom column to the custom post type edit screen, but can't seem to get the hook to work on the edit taxonomy page.

Digging through some of the core, I was able to locate the hook

$taxonomies = apply_filters( "manage_taxonomies_for_{$post_type}_columns", $taxonomies, $post_type );

inside of class-wp-posts-list-table.php which would lead me to believe it is possible to hook into, and add custom columns to this page. But when hooking in to add the column, nothing actually happenes.

function events_color_column($defaults) {
    $defaults['event_cat_color'] = 'Event Category Color';
    return $defaults;
}

function events_column_content($column_name, $post_ID) {
    if ($column_name == 'event_cat_color') {
       echo 'Event Color : #2432';
    }
}
add_filter('manage_taxonomies_for_events_columns', 'events_color_column');
add_action('manage_taxonomies_for_events_column', 'events_color_column_content', 10, 2);

but if I simply change the filter+action to 'manage_events_columns' and 'manage_events_column' things work on the custom post type screen.

Can someone see what I am doing wrong here, or is this a bug that needs to be patched in core?

Edit:

I was able to hook into the custom taxonomy page to display the column header, by doing the following:

To any one else facing similar issues, you need to pass in the page ID. For me, the following worked:

  add_filter('manage_edit-event_categories_columns', 'events_color_column');

But I can't seem to figure out why the content isn't printing into each column using

  add_action('manage_edit-event_categories_custom_column', 'events_color_column_content', 10, 2);

I have also tried passing in the taxonomy name, the post type name, but nothing seems to work. What am I missing here?

Topic columns core taxonomy Wordpress

Category Web


The final working hooks that I was able to work out are:

// adding an extra column to the event_cateogires page
// to display the color
function events_color_column($defaults) {
    $defaults['event_cat_color'] = 'Event Category Color';
    return $defaults;
}

function events_color_column_content($column_name, $post_ID) {  
    echo 'Event Color : #2432';
}
add_filter('manage_edit-event_categories_columns', 'events_color_column');
add_action('manage_event_categories_custom_column', 'events_color_column_content', 10, 2);

Using the

if ($column_name == 'event_cat_color') {
       echo 'Event Color : #2432';
    }

didn't seem to work with this action hook. Removing the conditional, and just echoing things out seems to work.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.