Wordpress 获取没有分类名称的分类术语

Wordpress 获取没有分类名称的分类术语,wordpress,Wordpress,我试图显示自定义帖子类型的分类术语(如在常规帖子中使用)。下面的代码可以工作,但需要指定分类名称,有没有办法只使用Post ID <?php $terms = get_the_terms( $post->ID , 'taxonomy_name' ); foreach ( $terms as $term ) { echo $term->name; } ?> 提前谢谢 <?php print the_terms( $post->

我试图显示自定义帖子类型的分类术语(如在常规帖子中使用
)。下面的代码可以工作,但需要指定分类名称,有没有办法只使用Post ID

<?php

   $terms = get_the_terms( $post->ID , 'taxonomy_name' );
   foreach ( $terms as $term ) {
     echo $term->name;
   }
?>

提前谢谢


<?php print the_terms( $post->ID, 'taxonomy_name' , ' ' ); ?>

没有分类名称,您无法获取自定义分类术语,但上面的代码对您来说比较短。

我找到了一种方法。使用“get_post_分类法”并选择数组witch cat[1]

<?php  

$cat = get_post_taxonomies($post);
$terms = get_the_terms( $post->ID , $cat[1] );

// Loop
if ( $terms != null ){

   foreach( $terms as $term ) {
   $term_link = get_term_link( $term, $cat[1] );

   // Print the name and URL
   echo '<a href="' . $term_link . '">' . $term->name . '</a>';

   unset($term); } }

?> 

试试这个

 $term_list = wp_get_post_terms($post->ID, 'my_taxonomy', array("fields" => "names"));
    print_r($term_list);
您必须使用没有分类的分类法,分类法无法获取术语详细信息


谢谢你

你好@Gazi,谢谢你的回答。我找到了一个办法。在foreach循环之前使用它:$cat=get\u post\u分类法($post)$术语=获取术语($post->ID,$cat[1]);