【自分用メモ・WordPress】カスタム投稿のカテゴリ取得

WordPressのカスタム投稿のカテゴリを取得する場合のメモ。
リンクありとリンクなしの場合を書いておく。
目次
リンクあり
<?php get_the_term_list( $id, $taxonomy, $before, $sep, $after ) ?>
/*
$id : 投稿ID(整数, 必須)
$taxonomy : タクソノミーの名前(文字列, 必須)
$before : 前に入れる文字列(文字列, オプション)
$sep : タームを区切る文字列(文字列, オプション)
$after : 後に続く文字列(文字列, オプション)
*/
リンクなし
<?php
if ($terms = get_the_terms($post->ID, 'カテゴリ名')) {
foreach ( $terms as $term ) {
echo esc_html($term->name);
}
}
?>
/*
get_the_terms( $id, $taxonomy );
オブジェクトを返す
stdClass Object
(
[term_id] =>
[name] =>
[slug] =>
[term_group] =>
[term_order] =>
[term_taxonomy_id] =>
[taxonomy] =>
[description] =>
[parent] =>
[count] =>
[object_id] =>
)
*/