Custom columns for taxonomy list table

I have the following code to add a new column to my taxonomy edit screen (edit-tags.php?taxonomy=book_place&post_type=books)

function add_book_place_columns( $columns ) {
    $columns['foo'] = 'Foo';
    return $columns;
}
add_filter( 'manage_edit-book_place_columns', 'add_book_place_columns' );

function add_book_place_column_content( $content ) {
    content = 'test';
    return $content;
}
add_filter( 'manage_book_place_custom_column', 'add_book_place_column_content' );

It’s working, but I need to access the current term id in the add_book_place_column_content function. How can I do that?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

The manage_{TAXONOMY}_custom_column filter hook passes 3 arguments:

  • $content
  • $column_name
  • $term_id

So try this:

function add_book_place_column_content($content,$column_name,$term_id){
    $term= get_term($term_id, 'book_place');
    switch ($column_name) {
        case 'foo':
            //do your stuff here with $term or $term_id
            $content = 'test';
            break;
        default:
            break;
    }
    return $content;
}
add_filter('manage_book_place_custom_column', 'add_book_place_column_content',10,3);


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments