Active
Project:
Views Custom Field
Version:
6.x-1.0
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
21 Jan 2010 at 03:05 UTC
Updated:
28 Jul 2013 at 04:37 UTC
I have created a view of stories, and I need to add an icon next to stories who's tid is 622.
I have added the field taxonomy term: all, and specified my vocabulary (since these stories have two vocabularies each), and am using the following code in Custom Field:
<?php
if($node->term_tid == "622") print "<img src=\"/images/breakingnewsgif\" border=\"0\" height=\"12\" width=\"12\" alt=\"Breaking News\">";
?>
I can't seem to get this to work no matter what I try. Anyone know how to find one specific taxonomy?
Comments
Comment #1
infojunkieTry
$datainstead of$node.Comment #2
djudd commentedThank you for the advice, but I'm afraid that didn't work either.
Any other ideas? I'm stuck here.
Comment #3
infojunkieYou should examine the contents of the
$dataobject (usingprint_rfor example) to find the name of the attribute you need.Comment #4
djudd commentedI really do appreciate that tip, and it worked wonderfully.
The problem is that Views apparently doesn't give the tid information when using Taxonomy Term: All, so I may just be out of luck here.
My fields are Title, Premium, and Taxonomy Term: All and this is what $data gives me...
stdClass Object ( [nid] => 84875 [node_title] => Fort battalion’s move to Texas to take $120M yearly toll [premium_nid] => [node_vid] => 84876 [nodequeue_nodes_node_position] => 2 )
Comment #5
nathanjo commentedWhere did you place that code? If you use the THEME suggestion from the views, you can check the $row and $field. Are you sure the node has taxonomy value? Did you check the "exclude from display" is not check for that field?
Comment #6
noslokire commentedAlas, after a long battle I got it to do what I wanted and since I suffered so, I hope this helps the next battered soul!
Comment #7
karljohann commentedI'm having the same problem. I would really prefer there was a way to do this without repeating the db query though...
Comment #8
infojunkieYou could use the taxonomy function
taxonomy_node_get_terms($node), like so:Comment #9
thommyboy commentedsame problem here. yes- there are workarounds using node_load but this will cause (unnecessary) db-queries. it seems to be a bug that a "taxonomy:all terms" field is not included into $data while "taxonomy:term" is?
Comment #10
dennys commentedAfter I got $terms, how could I got tid? I use $terms->tid, but it doesn't work. But print_r($terms) shows the correct tid in the array.
Comment #11
visheshd commented$terms is an array ... try using
$terms[actual-vocabulary-id]->tid;Comment #12
Renee S commentedI've found this too. I looks to me like a bug.
Comment #13
prototyp1278 commentedHi all ! I need custom php. Can somebody help me. i need some source like.
I need print custom text when one of node terms is term id 255.
Thanx 4 answers Pavel
Comment #14
avibrazil@gmail.com commentedI have the same problem. This is definitivelly a bug.
Comment #15
seanrThis is still a problem even now. Over a year since this was reported. Why on earth doesn't Taxonomy: All Terms get added to the data array? Should this maybe be reported to Views, or is this specific to Views Custom Field?
Comment #16
kalimero commentedHi everybody!
This bug is very annoying but I have a solution that despite of not being very elegant, doesn't involve node_load or make a query:
We must take advantage of $view parameter of function like that
Ok, I know this solution it's not ver classy but it works and we don't need call node_load or make a cost query
Ps: sorry for my bad english
Comment #17
skolesnyk commentedIssue with status 'won't fix'on Views Issues list. Wow.
http://drupal.org/node/443186
Comment #18
orjantorang commentedMy solution to the problem of not finding the term tid or term name in $data object is to add the display of the term name or term tid once again, even if you already have Taxonomy: All terms
Fields
Taxonomy: All terms Status
Node: Title Ticket
...
Customfield: PHP code PHP code (no terms visible in $data here)
Taxonomy: Term State name (add the term (name/tid) again)
Customfield: PHP code State (now you can find term data in $data)
[term_data_name] => BS_STILL_RUNNING
[term_data_vid] => 1
[term_data_tid] => 10
[term_data_weight] => 53
Comment #19
scotwith1tJust FYI, this causes problems if you're dealing with multiple value taxonomy. Otherwise it works fine.
Comment #20
scotwith1tduplicated