2021年1月15日

Wordpress 子・孫カテゴリIDを取得

親子間の子カテゴリ取得
$categories = get_the_category();
foreach ( $categories as $category ) {
  if($category->parent){
    $catename = $category->name;
    $childcateid = $category->cat_ID;
  }
}
親子孫間での特定の子カテゴリ取得
$cat = get_the_category();
foreach ( $cat as $category ) {
    $parent = $category->parent;
    if( $parent == ここにID ){
        $catename = $category->name;
        $childcateid = $category->cat_ID;// これもID
        $childcateid = $category->term_id;// これもID
    }
}
Wish I could be Comic Sans ついにマイコンピューターでインターネットを始めたの
わたしはヨガマットデザイナー

fzfeed