Hello,
I wrote a function so I could quickly add nodes by code.
Basically it builds a $node object and then uses node_save().
Everything is good until I try to add values to cck fields for that node... no success.
What I need is:
I have a cck field called 'subtitle' which I want to get an automatic value (based on node's title) when
the user adds a new node.
(I tried looking at the macro engine and use something like $node['field_subtitle'][0]['value'] = "something" but no luck)
Here is the function I am currently using to add nodes (I extracted it from the blogapi.module):
function lt_add_node($title,$type,$content,$userid,$username) {
$url = $title;
// Add the node
$edit = array();
$edit['type'] = $type;
// get the node type defaults
$node_type_default = variable_get('node_options_'. $edit['type'], array('status', 'promote'));
$edit['uid'] = $userid;
$edit['name'] = $username;
$edit['promote'] = in_array('promote', $node_type_default);
$edit['comment'] = variable_get('comment_'. $edit['type'], 2);
$edit['revision'] = in_array('revision', $node_type_default);
$edit['format'] = FILTER_FORMAT_DEFAULT;
$edit['status'] = 1;
$edit['title'] = $title;
$edit['body'] = $content;
$edit['taxonomy'] = array('tags' => array(1 => 'Unsorted', 136 => ''));