By li8461 on
I created a custom content type Car with cck, and would like to be able to post/create a Car node by using php script directly outside of Drupal, not from the web form created for this content type by the module. is it allowed? if so, can someone provide me some sample code? I have seen someone doing this within a new module, but not complete outside of the Drupal environment itself.
Comments
More than one way to do it, of course...
My approach was to install Devel module and use it to see the queries that were run during node creation for the particular content type. Then I created a script that ran those INSERTs and UPDATEs, pulling the appropriate data from another file or database.
I have imported from a csv file
I have imported from a csv file with this.
Hi, I'm trying to create
Hi,
I'm trying to create nodes programatically. I tried your code and works for some simple nodes, but in a content type I have a mandatory cck nodereference field and whenever I try to create a node of that type I get the following error:
Fatal error: Call to undefined function userreference_content_is_empty() in C:\wamp\www\drupal\sites\all\modules\cck\content.module on line 906
I've been reading around and there is people that suggest to use drupal_execute instead of node_save but I can't manage to get anything created using drupal_execute .
Anyone could point me on how to get those nodereference fields filled? Maybe someone could address me to some code for creating nodes using drupal_execute?
I think you could
I think you could do
without the quotes.
$values['values']['op'] = t('Save');
The quotes didn't change anything.
Actually the root of the problem was some module dependencies. I could only figure it out when I tried the drupal_execute approach.
For it to work, I found that you need to add
$values['values']['op'] = t('Save');
I'll leave this comment here just for the sake of documentation. The difference with the drupal_execute approach is that it will carry all the extra validation and module hooks involved whereas node_save won't. For bulk importing routines one may not want the checks to be applied and therefore the node_save approach would be better.
Tanks for your prompt reply anyway.