カテゴリー・ターム
$cat = get_the_category();
パラメータ ID 省略時は投稿データの投稿ID
$cat_id = $cat[0]->term_id;
$cat_name = $cat[0]->cat_name;
タームを設定
wp_set_object_terms($id, array( ‘new’ ), ‘archive’ );
親のカテゴリーをまとめて取得
$ancestors = get_ancestors( $cat_id, ‘category’ );
第一階層のカテゴリーのみ取得する場合は、
$ancestors = get_ancestors( 0, ‘category’ );
//子孫カテゴリーを取得
$childs = get_categories(array(‘parent’=>”$oya_id”));//
//リンクを取得
$link = get_category_link( $val->term_id );
パンくずリストを作成
$cat = get_the_category();
$cat_id = $cat[0]->cat_ID;
$ancestors = get_ancestors( $cat_id, 'category' );
$ancestors =array_reverse($ancestors);
array_push($ancestors, $cat_id);
echo '<div class="breadcrumb post-categories">';
echo '<a href="'.home_url().'">HOME</a> ';
foreach ($ancestors as $val){
$name = get_the_category_by_ID( $val );
$link = get_category_link($val);
echo '> <a href="'.$link.'">'.$name.'</a>';
}
echo '</div>';