Wordpress - How To Get Parent Category ID

后端 未结 3 810
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-08 04:11

Wordpress - How To Get Parent Category ID


my category is  
news
---->sport news

i have a post in

3条回答
  •  庸人自扰
    2021-02-08 04:41

    Simply, very simply.

    //firstly, load data for your child category
    $child = get_category(31);
    
    //from your child category, grab parent ID
    $parent = $child->parent;
    
    //load object for parent category
    $parent_name = get_category($parent);
    
    //grab a category name
    $parent_name = $parent_name->name;
    

    Study get_category

提交回复
热议问题