Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm wondering how to create a content from another content. I'll give an example, it will be easier to understand :

We have a content-type "Planning" which has three fields : 2 user references and one date, which can be multiple filled (let's say the dates are appointments). So in result, a planning will link 2 users and this node will display all the dates these 2 are supposed to meet.

Also, we have another content-type "Appointment".

I'd like that after the creation of the Planning, the appointments get automatically created, always linking the 2users.

First, I've looked into the module Flexi-Field but it doesn't create the node. Then I thought about Rules but I don't know how to create the multiple nodes Appointments due to the multiple date fields.

I know I could do it with Rules through a PHP custom code, but if there's any easier solution, I'd like to hear about them :-)

Thanks for any suggestion !

Cheers all !

share|improve this question
up vote 2 down vote accepted

If both your content types are defined for Plannning and Appointment already, you can easily create appoint nodes on-the-fly when a Planning node is saved.

You want to look at the following 2 references:

It would look something like this (NOT TESTED):

function mymodule_node_insert($node) {
  if ($node->type == 'planning') {
    foreach (element_children($node->field_appointment_dates) as $a_single_appointment_date) {
      $appt_node = new stdClass();
      $appt_node->type = 'appointment';
      $appt_node->language = LANGUAGE_NONE; // Or your language type ...
      $appt_node->title = 'Some new appointment';
      $appt_node->field_appointment_date = $a_single_appointment_date[0]['value'];
share|improve this answer
This is for Drupal 7. While the idea is the same, I'm sure the OP would appreciate an example in 6 as well. – rocketeerbkw Oct 9 '11 at 2:58
Hi sorry. new here :P You're right I didn't notice it was D6. I've actually only done this in D6. You still use (the D6 equivalent) hook_node() on $op==insert, and you basically create the node the extact same way ... :/ – tenken Oct 9 '11 at 5:46
Thank you tenken, thanks to you, i've found a way to do it ! It's a bit different from yours : the solution is in the other answer – jozi Oct 20 '11 at 17:24
function planning_nodeapi(&$node, $op) {
    if ($node->type == 'planning' && $op=='insert') {
    $txt = $node->field_plan_texte[0]['value']; // some text
    $user = $node->field_plan_user[0]['uid']; //user reference
    $date = $node->field_plan_dates[0]['value']; // date of appointments, even if multiples
    for ($i=0;$i<count($node->field_dates);$i++){
       $appt = new StdClass();
       $appt->type = 'appointment';
       $appt->uid = 1;
       $appt->title = "pd";
       $appt->field_appt_user[0]['uid'] = $user;
       $appt->field_appt_date[0]['value'] = $node->field_dates[$i]['value'];

This is valid for D6 ;-) Thanks @ tenken !

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.