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

Time:01-12

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'); 

what I want to accomplish

what I really really want to happen in detail

How to pull up the value handled by the ACF field using term id

CodePudding user response:

Check this link about ACF plugin options. https://www.advancedcustomfields.com/resources/get_field/

This example shows a variety of $post_id values to get a value from a post, user, term and option.

$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 );
  •  Tags:  
  • Related