分类列表表的自定义列


13

我有以下代码将新列添加到分类编辑屏幕(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' );

它正在工作,但是我需要在add_book_place_column_content函数中访问当前的术语ID 。我怎样才能做到这一点?

Answers:


20

所述manage_{TAXONOMY}_custom_column过滤器通过钩3个参数:

  • $content
  • $column_name
  • $term_id

所以试试这个:

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);
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.