Database 创建节点wuth术语引用标记
我正在尝试用术语引用自动完成术语小部件(标记)以编程方式添加节点,并添加新标记“我的代码不工作” 当我从代码中删除标记引用时,我的节点添加成功 我需要为每个节点添加新标记Database 创建节点wuth术语引用标记,database,drupal-7,Database,Drupal 7,我正在尝试用术语引用自动完成术语小部件(标记)以编程方式添加节点,并添加新标记“我的代码不工作” 当我从代码中删除标记引用时,我的节点添加成功 我需要为每个节点添加新标记 <?php $bodytext = "body?"; $node = new stdClass(); // Create a new node object $node->type = "programstvradio"; // Or page, or whatever
<?php
$bodytext = "body?";
$node = new stdClass(); // Create a new node object
$node->type = "programstvradio"; // Or page, or whatever content type you like
node_object_prepare($node); // Set some default values
// If you update an existing node instead of creating a new one,
// comment out the three lines above and uncomment the following:
// $node = node_load($nid); // ...where $nid is the node id
$node->title = "title";
$node->language = LANGUAGE_NONE; // Or e.g. 'en' if locale is enabled
$node->uid = 1; // UID of the author of the node; or use $node->name
$node->body[$node->language][0]['value'] = $bodytext;
$node->body[$node->language][0]['format'] = 'filtered_html';
// I prefer using pathauto, which would override the below path
$path = 'node_created_on' . date('YmdHis');
$node->path = array('alias' => $path);
$node->field_tag_[$node->language][]['value'] ='tagggggggg';
$node->field_catprogram[$node->language][]['tid'] =12;
$file_path = drupal_realpath('C:\Users\Admin\Desktop\drupal.png'); // Create a File object'); // Create a File object
$file = (object) array(
'uid' => 1,
'uri' => $file_path,
'filemime' => file_get_mimetype($file_path),
'status' => 1,
);
$file = file_copy($file, 'public://images'); // Save the file to the root of the files directory. You can specify a subdirectory, for example, 'public://images'
$node->field_image[LANGUAGE_NONE][0] = (array)$file; //associate the file object with the image field:
if($node = node_submit($node)) { // Prepare node for saving
node_save($node);
echo "Node with nid " . $node->nid . " saved!\n";
}
?>``
我找到了解决办法
$my_term_name = 'gggg';
$term_array = taxonomy_get_term_by_name($my_term_name);
if($term_array == array()){
//empty term ..
$term->name = $my_term_name;
$term->vid = 1;
taxonomy_term_save($term);
$term_array = taxonomy_get_term_by_name($my_term_name);
}
//get the first index of the array .
foreach ($term_array as $tid => $term_object)break;
$node->field_progna['und'][$tid] = (array)$term_object;