开发者

Handling taxonomy fields in drupal7

The taxonomy system changed a lot since Drupal 6. What is the best way to get all taxonomy term IDs associ开发者_开发技巧ated with a single node in Drupal 7?


$node = node_load($nid);
$terms = field_view_field('node', $node, 'field_tags', array('default'));


Where do you want to get these terms ? In a module, a theme ...?

Did you take a look at : http://api.drupal.org/api/drupal/modules--taxonomy--taxonomy.module


The field_data_field_tags table just covers the default Tags field, that might or might not exist and you might have other taxonomies too.

However, taxonomy.module still maintains the taxonomy_term_data/taxonomy_index tables which you can query:

SELECT tid FROM {taxonomy_index} WHERE nid = :nid

Or if you want a specific vocabulary ID:

SELECT ti.tid FROM {taxonomy_index} ti INNER JOIN {taxonomy_term_data} ttd ON ttd.tid = ti.tid WHERE ti.nid = :nid AND vid = :vid

Completely untested.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜