tags:

views:

911

answers:

2

Hi guys,

I need to know the type of the tid in the term_data table. For example, I want to know if this tid is a type of the ed-classifieds module?

This is my query right now that is not 100% correct

# get all the parent categories for the ed classifieds
SELECT th.tid, td.name, n.type
FROM term_hierarchy th 
LEFT JOIN term_data td ON th.tid = td.tid 
LEFT JOIN term_node tn ON tn.tid = td.tid 
LEFT JOIN node n ON n.nid = tn.nid
WHERE th.parent = '0' 
#AND n.type = 'ed_classified' 
GROUP BY th.tid

Thanks in advance

+6  A: 

There might be a bit of confusion here. Terms themselves are just free-floating entities, like free tags or categories. They can be grouped into 'vocabularies' -- the vocabulary id is stored in the 'vid' column of the term_data table.

The 'node type' you're pulling up in that query is the content type of the node that is tagged with the taxonomy term. That type isn't inherent to the term itself -- a given term can be used to tag many different types of content at the same time. A term can only belong to a single vocabulary, though.

Eaton
Thanks Eaton for the clarification :) So you are trying to say that 'tid' simply has no type? Am I correct?Anyway, I tried this and it worked. It pulled off the parent categories of the classified ads. $cats = taxonomy_get_tree(_ed_classified_get_vid(), $tid, -1, 1);
marknt15
I think. There are two things you seem to be talking about -- the Vocabulary the term belongs to, the 'parent term' if a given term is part of a hierarchical tree of terms, and the term that a given node is connected to.taxonomy_get_tree() pulls up a hierarchy of all the terms in a vocabulary. taxonomy_get_parents() gets the parent term of a given term. And taxonomy_get_node_terms() gets the taxonomy terms a node has been tagged with. Check out http://api.drupal.org and search for 'taxonomy_get_' -- it should pull up a number of utility functions that may be useful for you.
Eaton
+2  A: 

In addition to what eaton said (and which is correct, as usual), note that term_node is joined to node by nid+vid and not only by nid: terms are revision-dependent since Drupal 6.

So your last join should be on n.vid = tn.vid instead of n.nid = tn.nid

FGM

related questions