只显示选中的自定义分类法类别

Only show checked categories of Custom Taxonomy

我正在尝试在模板页面上显示名为 standard_engine_specification 的自定义分类法的名称类别。这是我目前所拥有的——它显示了分类法的所有类别,而不仅仅是显示在管理面板中选中的类别。

<?php
/*variable to retrieve checked term*/

 $ses_terms = get_the_terms( $id, 'standard_engine_specification' );
  if( $ses_terms && !is_wp_error( $ses_terms ) ) {
  foreach( $ses_terms as $term ) {

   }
  }
  /*variable used to filter results*/
  $ses_args = array(
  'taxonomy'     => 'standard_engine_specification',
  'hierarchical' => true,
  'tax_query' => array(array(
   'taxonomy' => 'standard_engine_specification',
   'field' => 'slug',
   'terms' => array($term->slug),
   'operator' => 'IN'
  ))
 );
    
?>
<ul>
<?php
/*output checked categories based on filter*/
foreach (get_categories($ses_args) as $category)
 {
  echo "<li>";
  echo $category->name;
  
  echo "</li>";
  
 }
?>
</ul>

我已经从我一直用于过滤 post 类型的其他一些脚本中得到了相当多的科学怪人,也许知道他们在做什么的人可以告诉我在哪里以及为什么我错过了这个 - 我有发表一些评论。

确定了。我不需要使用 tax_query,我尝试做与将 WooCommerce 调用到模板页面上所做的相同的事情,但它太过分了,所以我们学习 :)

<?php

$ses_terms = get_the_terms( $post->ID, 'standard_engine_specification' );
if( $ses_terms && !is_wp_error( $ses_terms ) ) {
 foreach( $ses_terms as $term ) {
  echo "<li>";
  echo $term->name;
  echo "</li>";
 }
}
?>