完成ソース
<?php
$terms = get_the_terms($post->ID, 'タクソノミースラッグ');
if(!empty($terms)) {
foreach($terms as $term):
echo $term->name;
endforeach;
} else {
echo '未分類';
}
?>
他の取得方法
<?php
$terms = get_the_terms($post->ID,'タクソノミースラッグ');
foreach( $terms as $term ) {
echo $term->term_id; // タームID
echo $term->name; // タームの名前
echo $term->slug; // タームスラッグ
echo $term->term_group; // 親タームのタームID(↓の'parent'としても格納される)
echo $term->term_taxonomy_id; // タームが属するタクソノミーのID
echo $term->taxonomy; // タームが属するタクソノミーの名前
echo $term->description; // タクソノミーの説明
echo $term->parent; // 親タームのタームID(↑の'term_group'としても格納される)
echo $term->count; // このタームが使われている回数
}
?>
コメントを残す