【WP】カテゴリー、タームの取得など
2021年8月4日
スラッグからタームの情報を取得
$this_slag = 'slug_name';
$taxonomy = 'taxonomy_name';
$this_term = get_term_by('slug', $this_slag, $taxonomy);
$term_id = $this_term->term_id;
$term_name = $this_term->name;
カテゴリー
$cat = get_the_category(); $slug = $cat[0]->slug; $name = $cat[0]->cat_name;
ターム
$term = get_the_terms($post->ID,'taxonomy_name'); $slug = $term[0]->slug; $name = $term[0]->name;
