Custom Taxonomy Meta Admin Column

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.

Read More

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!

Related posts

1 comment

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

Comments are closed.