I'm here still learning with drupal 7 but now I have a new question about a node create programmatically,I hope you can help me.
I want to generate all node fields names programmatically and then set a lavue on each one.
To store each field from node I generate the names of the field witn an array with each name, this is because I want to make function to indicate the names of the fields of the node that I want to fill.
The problem is that my code is not working to fill the nodes, maybe because my fields names are bad generated. I generate and fill them this way:
$nodefields = array('areaid', 'areaname');
foreach ($nodefields as $fieldname) {
$node->$fieldname['und'][0]['value'] = $row->$fieldname;
}
node_save($node);
The rows are obtained by a query to a external db (column has the same name as the field), that's fine, the records are ok, if I fill them manually like:
$node->areaname['und'][0]['value'] = $row->$areaname;
Works ok, but I can't make it work with a loop to generalize that part.