如何从自定义帖子类型获取自定义类别 slug 和 id


How to get the custom category slug and id from custom post type?

我有一个自定义的帖子类型。它有一个自定义类别/分类法。它的名字是download_category即register_taxonomy('download_category',.....

我需要知道自定义帖子类型中特定帖子的自定义类别 ID 和 slug。

例如,如果 120 是我的自定义帖子类型 ID,那么我如何在download_category分类法下获取自定义帖子类型的分类。请帮忙

$terms = get_the_terms(120, 'download_category' );

print_r($terms );

看到结果.

通过使用

get_the_terms( 120, $taxonomy );

获取自定义帖子类型的分类