2010-08-26 30 views
0

我試圖填充通過編寫腳本節點...我使用下面的代碼如何插入到一詞命名的詞彙標籤

$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做的是什麼並沒有被添加術語詞彙命名標籤...如果我寫下面的代碼,它會選擇已經存在的術語調用xml ..我猜是因爲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); 

有人可以幫助我如何添加術語到已經存在的詞彙

+0

問題的標題是動態VID要求什麼,而問題是要求別的。將詞條插入詞彙表與填充節點不同;實際上,要將詞條插入詞彙表中,您不需要任何節點對象。 – kiamlaluno 2010-08-26 18:47:40

+0

其實我正在解釋我在做什麼..可能是我錯了....在詞彙表中保存術語是部分....問題是,我知道如何在drupal 6中做到這一點,但不知道如何在drupal 7中完成。有人請引導我 – 2010-08-26 18:56:09

回答

0

閱讀數百行代碼

$後得到了它terms = new stdClass(); $ terms-> vid = 1; $ terms-> name ='success'; $ get_tid = new stdClass();

taxonomy_term_save($ terms);

術語將保存詞彙VID = 1自動TID ....

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