5

I've added a custom taxonomy - shop_departments which is hierarchal. I've then added a meta field to this new taxonomy - term_meta[front_page] - which is all working fine.

However, on the management screen for the taxonomy I want a column for this meta data so the user can see at a glance which departments are assigned to the front page.

I can't work out how to add a column to this page. I want to do something like:

// Register the column
function front_page_column_register( $columns ) {
$columns['front-page'] = __( 'Front Page', 'my-plugin' );

return $columns;
}
add_filter( 'manage_edit-shopp_department_columns', 'front_page_column_register' );

Any help would be great, all the articles i've found talk about adding it to a posts or custom post-type edit page, not the taxonomy page itself!

2
  • I don't see a filter available in the get_columns() method for WP_Terms_List_Table class, so unless I am mistaken, I don't think it is possible. This would be a cool feature though. Heck, I'd add it myself if WordPress would ever switch to github. I'm useless on the SVN system. Commented Dec 19, 2013 at 22:14
  • I disagree, it must be possible. That filter i've posted above is described here and used in the plugin Taxonomy Images but for some reason it's not working for me.
    – Ralphonz
    Commented Dec 20, 2013 at 10:58

1 Answer 1

8

I managed to work it out. Seems like the filters only work when wrapped in an 'admin_init' action. My final code to add an admin column for the custom taxonomy meta 'front_page' to the custom taxonomy 'shopp_department' in my themes' functions.php

// Register the column
function department_add_dynamic_hooks() {
$taxonomy = 'shopp_department';
add_filter( 'manage_' . $taxonomy . '_custom_column', 'department_taxonomy_rows',15, 3 );
add_filter( 'manage_edit-' . $taxonomy . '_columns',  'department_taxonomy_columns' );
}
add_action( 'admin_init', 'department_add_dynamic_hooks' );

function department_taxonomy_columns( $original_columns ) {
$new_columns = $original_columns;
array_splice( $new_columns, 1 );
$new_columns['frontpage'] = esc_html__( 'Front Page', 'taxonomy-images' );
return array_merge( $new_columns, $original_columns );
}

function department_taxonomy_rows( $row, $column_name, $term_id ) {
$t_id = $term_id;
$meta = get_option( "taxonomy_$t_id" );
if ( 'frontpage' === $column_name ) {
    if ($meta == true) {
        return $row . 'Yes';
    } else {
        return $row . 'No';
    }   
}

Hope this helps someone.

Your Answer

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

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