get_term 或 get_term_by 不起作用 - 我在分类法之外,也不在 single.php 内

get_term or get_term_by is not working - I am outside the taxonomy nor inside a single.php

function sub_menu_industry_products_feat_func($atts) { 
      $atts = shortcode_atts( array( 'feat_img_slug' => ''), $atts ); 
      $term_id = $atts["feat_img_slug"]; 
      // term id is being fetched here .... 
      return get_term_by( 'id', $term_id, 'industry_product' )->name; 
  } 
  add_shortcode('sub_menu_industry_products_feat', 'sub_menu_industry_products_feat_func'); 

检查此 link 关于 ACF 插件选项。 https://www.advancedcustomfields.com/resources/get_field/

此示例显示了各种 $post_id 值,以从 post、用户、术语和选项中获取值。

$post_id = false; // current post
$post_id = 1; // post ID = 1
$post_id = "user_2"; // user ID = 2
$post_id = "category_3"; // category term ID = 3
$post_id = "event_4"; // event (custom taxonomy) term ID = 4
$post_id = "option"; // options page
$post_id = "options"; // same as above

$value = get_field( 'my_field', $post_id );