By f1vlad on
Hi guys,
I am quite confused how you obtain $nid from $node->taxonomy. I will explain why. Here's print_r($node->taxonomy) from two different nodes:
Array
(
[2] => stdClass Object
(
[tid] => 2
[vid] => 1
[name] => How to apply
[description] =>
[weight] => 0
)
)
Array
(
[1] => stdClass Object
(
[tid] => 1
[vid] => 1
[name] => About us
[description] =>
[weight] => 0
)
)
Notice "[1] => stdClass Object", in the square brackets, there are different numbers always, either 1 or 2 or whatever else. How do I know how to access nid variable?
If I do this it will work in one node but not the other:
$tid=$terms[1]->tid;
Am I doing something wrong? I searched and searched but can't seem to understand how to grab that variable. I could just write my own DB query, but think it won't be the most optimal thing to do. Please give me some ideas if you know what I am talking about.
Thanks,
Vlad
Comments
I just played around with
I just played around with this thing and here's what I managed to get to work, I don't know however if this is a correct way to do it:
The index to $node->taxonomy is the tid.
You seem to be assuming there is always one term associated with the node which may not be the case. If what you want are just the tids for the terms associated with the node you could do
which will get you the set of tids as an array. If you just want the first tid you could do something like this
Hey thanks, yeah that's the
Hey thanks, yeah that's the idea, there's only going to be one one tid associated with the node. That's how we've developed it. So in my case I only care about the first tid, if for some reason more tids are there, I just need the first one there is.
So what I ended up doing is this, my friend wrote a small code for me which I liked:
This worked great for me
This worked great for me using it to embed a page view into a node.