By anantagati on
Hi, I am converting NAT module to Drupal 7 and would like to know if there is some easy (good performing) way how to get terms which are associated with node.
Currently I found these two ways:
1) Make db_query and get associated terms for specific node and vocabulary.
2) Use field_info_fields() and find what is the name of field associated with specific vocabulary. Then read value from that field ($node->field_xxxxx) to get term ids.
Those two methods doesn't seem practical as there is already field_xxxxxxx in $node object which contain wanted information, but I cannot find existing function to get name of the field for specific taxonomy vocabulary.
Comments
can this article help?
can this article help? http://drupal.org/node/76392
--------------------------------------------------------------------------------------------------------
if you can use drupal why use others?
VicTheme.com
Can help, but not for Drupal
Can help, but not for Drupal 7.
So, I went with 2) to get
So, I went with 2) to get fieldname and then get values directly from $node object.
_
What about passing nid to http://api.drupal.org/api/function/taxonomy_term_load_multiple/7 ?
Has anyone got a solution for
Has anyone got a solution for this? It seems a common question and there are a number of different Drupal 6.x solutions that seem to work well. The main complication, is that all of the taxonomy functions relating to nodes have been removed, and seem to have been replaced either with the complicated Fields API, or with Views.
The main question is, how can you just do what taxonomy_node_get_terms did in 6 in 7? Must be simple, but I can't figure it out.
@WorldFallz http://api.drupal.org/api/function/taxonomy_term_load_multiple/7 seems like it might work, but can you pass a condition that selects based on NID?
UPDATE -- I realize this is a crazy thing to do, but I slapped together a module which tweaks taxonomy_select_nodes() a bit, and instead of selecting all of the nodes connected with a term, it selects the terms connected with a node. I tried to follow all the debate about the Fields API, but couldn't really figure it out. I'd be grateful if someone sketched out the correct way to do this sort of thing. I have a hunch as more and more people start rolling things into Drupal 7, people will be asking.
Anyhow, here's the tweaked code:
saved by Pro Drupal 7 Development
A variation on the following worked for me, (credit goes to page 355 of Pro Drupal 7 Development):
no 'field_tags', so...
I didn't have a field named 'field_tags', so this call didn't return anything for me. I was trying to use a series of taxonomy relationships that did survive a D6 upgrade. I noticed that my node variable did have 'taxonomy_vocabulary_N' fields, so I put this hack together: