marinex
marinex

Reputation: 5

Add taxonomy terms directly to node through SQL (term_node)

How can I add taxonomy terms directly to a node through SQL?

I used:

db_query("INSERT INTO {term_node} (nid, vid, tid) VALUES ( " . $row['nid'] . "," . $the_term->vid . "," . $row['next_tid'] . ")" );

The values $row['nid'], $the_term->vid and $row['next_tid'] are correct; but still no terms appear in the node.

Upvotes: 0

Views: 1376

Answers (2)

DoppioGancio
DoppioGancio

Reputation: 1

Are you guys talking about Drupal 7? In that case you should consider at least two more tables. CCK in Drupal 7 creates two tables for each field: field_data_field_<fieldname> and e field_revision_field_<fieldname>

Upvotes: 0

Boriana Ditcheva
Boriana Ditcheva

Reputation: 2015

Instead of writing directly to the db, why not call the taxonomy_node_save() method instead: http://api.drupal.org/api/drupal/modules!taxonomy!taxonomy.module/function/taxonomy_node_save/6

This way you can make sure you're not missing any additional steps that function does (even as small as 'flushing the term cache' at the end. :-)

Let me know if that works out!

Upvotes: 2

Related Questions