Posted by ubuntu on March 29, 2008 at 7:35am
I used admin GUI to create a new content type "my_type", then I added CCK fields. Does anyone know how to create a node of "my_type" using php programmatically?
I used drupal_execute() to create node before, but it requires a form id. In that case, the content type was defined by a module, which contained a form for the content type. I don't know what form id to use for a type created using GUI with CCK fields.
Another method of creating node is to use node_save(). I haven't figured out how to use either method for content type with CCK fields. Any help is greatly appreciated.
Thanks.
Comments
here is your solution :)
http://www.civicactions.com/blog/cck_import_and_update
That is the "best" method of how to do it...
There is also a lot of great discussion in http://lists.drupal.org/pipermail/development/2008-March/029148.html
knaddison blog | Morris Animal Foundation
node_factory module
I hope some common sense will land in this module. This is far from complete though.
See also http://drupal.org/node/231922 for an abstract of the discussion mentioned by greggles.
Multiple values field
Hello,
I know that for a simple field, this works:
<?php$node->field_soft_license[0]['value'] = $lic;
?>
But if this is a multiple values field (selected by checkboxes), I try this:
<?phpforeach ($licenses as $lic) {
$node->field_soft_license['value'][$lic] = $lic;
}
?>
However it doesn't work :( I use node_save instead of drupal_execute as I think the latter has some problems with Batch API.
--
[vi] www.thongtincongnghe.com
Trang tin điện tử về CNTT, Viễn thông, Điện tử...
My bad, I change to <?php
My bad, I change to
<?php$node->field_soft_license[$i++]['value'] = $lic;
?>
--
[vi] www.thongtincongnghe.com
Trang tin điện tử về CNTT, Viễn thông, Điện tử...