get_the_terms child terms for current postcustom post only

Inside a PostCustom Post type loop, I am trying to get child terms selected on the edit screen of that postcustom po

Inside a Post / Custom Post type loop, I am trying to get child terms selected on the edit screen of that post/custom post.

For Example:

  1. Zoologist ( Parent )

    • Pre Zoologist
    • Post Zoologist

Now if for any specific post / custom post if users selected all of above taxonomies including Zoologist (Parent), Pre Zoologist, Post Zoologist.

Using get_the_terms function i only want to get child taxomony, in this case Pre Zoologist, Post Zoologist.

I tried this code but it is not working:

$terms = get_the_terms( get_the_ID(), 'custom_taxonomy' );

  foreach ( $terms as $term ){
  if ( $term->parent == 0 ) {
    echo '<div class="parent '.$term->slug.'">' . $term->name . '</div>';
  }

}

Please let me know where am I making a mistake.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745309013a4621886.html

相关推荐

  • get_the_terms child terms for current postcustom post only

    Inside a PostCustom Post type loop, I am trying to get child terms selected on the edit screen of that postcustom po

    9小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信