如何将术语插入名为Tag的词汇表中

时间:2010-08-26 18:05:45

标签: drupal drupal-7

我正在尝试通过编写脚本来填充节点...我正在使用以下代码

$node->field_tags['und'][0]['textfield'] = 'first_tag';
$node->field_tags['und'][0]['textarea'] = 'This is tag';
$node->field_tags['und'][0]['tid'] = 2;
node_save($node);

whatsits做什么都没有,这个词没有被添加到词汇名为tag ...如果我写下面的代码,它会选择已经存在的术语调用xml..i猜测因为tid = 1;

$node->field_tags['und'][0]['textfield'] = 'first_tag';
$node->field_tags['und'][0]['textarea'] = 'This is tag';
$node->field_tags['und'][0]['tid'] = 2;
node_save($node);

我甚至尝试过以下代码

$node->field_tags['und'][0]['name'] = 'first_tag';
$node->field_tags['und'][0]['description'] = 'This is tag';
$node->field_tags['und'][0]['tid'] = 2;
node_save($node);

有人可以帮助我如何在已存在的词汇中添加术语

2 个答案:

答案 0 :(得分:1)

使用以下功能

动态获取视频
$vid = taxonomy_vocabulary_machine_name_load('vocabname');
$terms = new stdClass();
$terms->vid = $vid; 
$terms->name='whatever name of your term'; 
taxonomy_term_save($terms);

谢谢, Ankush

答案 1 :(得分:0)

在阅读了数百行代码后得到了它

$ terms = new stdClass(); $订条款─> VID = 1; $订条款─>名称= '成功'; $ get_tid = new stdClass();

taxonomy_term_save($术语);

术语将保存在词汇表vid = 1中,并带有自动tid ....

相关问题