Display a flag link in views based on whether the node has an associated taxonomy term All of my nodes of a certain content type are given a category by assigning a taxonomy term. I would only like to add the flag, "My Fruits" if the content has the term "Fruit" assigned to it.

So far I've attempted using a views PHP field to add the flag:

This works to simply print the flag:

&lt;?php 
print flag_create_link("basket_01_t01_fruit", $row-&gt;nid);
?&gt; 


But this, I'm not able to get working:

&lt;?php 
if ($row-&gt;field_item_produce_type == '3') {
print flag_create_link("basket_01_t01_fruit", $row-&gt;nid);
}
?&gt; 


Any ideas would be appreciated.
You could achieve this easily using views without using views php field. More specifically you can create a view of content with an EVA (entity views attach) field display where you will add the flag link field and attach it to the nodes of that content type. Just make sure to:


Add a contextual filter of Content:Nid
Add a relationship of "Content:Taxonomy terms on node"
Also add a "Flags: Node flag" relationship (uncheck the include flagged content only checkbox)
Add a filter "Content type:...your content type which nodes will have the flag link 
Add a filter "Taxonomy term: Term ID" that will equal to the tid of the "fruit" term.


After that you can easily choose how to display this eva field on your nodes using Display suite.