skip to Main Content

I have this code to display term metadata but for some reason, it’s not showing up / Data is blank Sorry for not making it clear the first time

UPDATED

    if ( 'new_column2' == $column_name ) {
/*Begin*/
foreach((get_term_meta( $post->ID, 'crosssell' )) as $category) {
    $cat_name = $category->name . '</br>';
    $cat_id = $category->term_id . '</br>';
    $crosssell = get_term_meta( $cat_id, 'crosssell', true );
    }
/*End*/
    
 $value = $crosssell;
 }
 return $value;
 }

what am i doing wrong

2

Answers


  1. Chosen as BEST ANSWER

    This fixed the problem I had.

    if ( 'new_column2' == $column_name ) {
    /*Begin*/
        
         $prod_cat_args = array(
      'taxonomy'     => 'product_cat', //woocommerce
      'orderby'      => 'name',
      'empty'        => 0
    );
    
    //$woo_categories = get_categories( $prod_cat_args );
    $woo_categories = get_the_terms( $post->ID, 'product_cat' );
    
    foreach ( $woo_categories as $woo_cat ) {
        $woo_cat_id = $woo_cat->term_id; //category ID
        $woo_cat_name = $woo_cat->name; //category name
    }
        $cat_term_id = $woo_cat_id;
        $crosssell = get_term_meta( $cat_term_id, 'crosssell', true );
    /*End*/
        
     $value = $crosssell;
        }
     return $value;
     }
    

  2. You’re assigning variables but not actually outputting anything.

    foreach( ( get_term_meta( $post->ID, 'crosssell' ) ) as $category ) {
        echo $category->name . '</br>';
        echo $category->term_id . '</br>';
        echo get_term_meta( $category->term_id, 'crosssell', true );
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search