By ardas on
Greetings,
How can I add a new CCK node instance from PHP snippet just like it was created from an admin form?
My CCK node consists of Title, field_1 (numeric field), field_2 (string field) and field_3 (user reference field).
As I understood I need to call node_save($node) function to either insert a new or update an existing node. But how should I initialize $node class to save CCK data as well?
Thanks.
Comments
ditto
I am also wondering about this. I found a snippet somewhere that looked like this:
(there was some error checking too)
But this just saves some empty node into the database, my data doesn't get inserted.
Also, how do I select the type? (eg. content_mytype)
yay
Ah. Looking into how the Leech module does things, it seems like this works:
There are other fields to set up too, but at least it got saved with "sometitle" now... does that help you out?
I'm still not sure how to set up the actual CCK fields, but I'm guessing one does that with something like
$node->field_myfield = "foobar";(although I haven't tested enough to find out yet).(If someone knows where there's a tutorial for programmatically saving nodes, or wants to write one, please let me know...)
Thanks!
This is exactly what I was looking for ... I'll try this approach.
----------------
Regards,
Dmitry Kresin, ARDAS group (www.ardas.dp.ua)
http://drupal.org/node/82661#
http://drupal.org/node/82661#comment-153461 there's more info here on CCK fields. CCK fields store things in arrays, meaning assignments look like this:
Use the devel module to find those structures (this module lets you see the Object Structure for each node).