following code is returning name
of all terms associated with my custom Post Type which are under `generetax taxonomy only
$terms = get_the_term_list($post->ID, 'generetax');
echo $terms;
Can you please let me know how to get the term_id
instead of name? I tried this way
echo $terms->term_id;
but it is not returning any thing
**
Update
**
Ok On rnnung this method
$terms = get_the_terms($post->ID, 'generetax');
foeach($terms as $term){
print_r($term);
}
WP_Term Object ( [term_id] => 3 [name] => Semi [slug] => semi [term_group] => 0 [term_taxonomy_id] => 3 [taxonomy] => generetax[description] => [parent] => 0 [count] => 1 [filter] => raw )
but still $terms->term_id;
return nothing on
$terms = get_the_terms($post->ID, 'generetax');
foeach($terms as $term){
echo $terms->term_id;
}
foreach($terms as $term){print_r($term);}
that should tell you what's going on. You can't echo an array, useprint_r
,var_dump
, orvar_export
instead, then you'll know if it's an object or an array & what it contains..Warning: Invalid argument supplied for foreach()
get_the_term_list
returns string.get_the_terms
will return an array of terms for a given taxo/post_id.get_terms
will return all terms for a given-taxo.