How to print taxonomy term name with views PHP? I have a views that include node title, a text field and a taxonomy term reference field.

I need to print the taxonomy term name via Global: PHP field (Views PHP) but I couldn't.

How to print taxonomy term name with Views PHP?





I can print the node title with that code:

Value Code:

return $row-&gt;title; 


Output Code:

&lt;?php print $value; ?&gt;




or without Value Code:

Output Code:

&lt;?php print $row-&gt;title; ?&gt;




And I could print the taxonomy term ID with that code:

Output Code:

&lt;?php print $data-&gt;field_field_my_taxonomy_term[0]['raw']['tid']; ?&gt;



But using name or value instead of tid doesn't return anything.



I also tried to print the term name with these ones but unfortunately none of them worked:

$data-&gt;field_my_taxonomy_term[0]['raw']['value'];


(Above code prints nothing.)



&lt;?php $data-&gt;field_my_taxonomy_term[0]['raw']['taxonomy_term']-&gt;name; ?&gt;


(Above code prints nothing.)



So, I'm confused now and not know how to print taxonomy term name with Views PHP?


Note: I looked at these but still couldn't solve the problem:


Views Php how to select actual term name not term ID
https://www.drupal.org/node/1707002
https://www.drupal.org/node/1516348
Storing PHP code directly on database is not a correct method, it causes many issues. Better you can add the relations on your views - "Content: Taxonomy terms on node". and then add the taxonomy term name field as a "hidden field"

Print the value via "Global: Custom text" field if required any custom wrapper around of it.