カスタム投稿の場合、タグはカテゴリーと同じようにタクソノミーの概念って感じ??
newsってカスタム投稿にタグを追加したとして・・・
$args = array(
'label' => 'ニュースタグ',
'rewrite' => array( 'slug' => 'example' ),
'show_in_rest' => true,
'hierarchical' => true,
);
register_taxonomy('news_tag','news',$args);
管理画面の投稿一覧に出すのは下記のコード
function add_custom_column_news_tag( $defaults ) {
$defaults['news_tag'] = 'タグ';
return $defaults;
}
add_filter('manage_news_posts_columns', 'add_custom_column_news_tag');
function add_custom_column_id_news_tag($column_name, $id) {
if( $column_name == 'news_tag' ) {
if ($terms = get_the_terms($post->ID, 'news_tag')) {
foreach ( $terms as $term ) {
echo '' .$term->name. '';
}
}
}
}
add_action('manage_news_posts_custom_column', 'add_custom_column_id_news_tag', 10, 2);