I have a collection of nodes that are created programmatically after having created the content type using Drupal. This is the creation code:

    $node = new stdClass();
    $node->title = $vals->title;
    $node->type = "event_type";
    $node->status                       = 1; 
    $node->promote                      = 0; 
    $node->comment                      = 0; 
    // title
    $node->title = $vals->title;
    // body     
    $node->body[$node->language][0]['value']   = $vals->body;
    $node->body[$node->language][0]['summary'] = text_summary($vals->body);
    $node->body[$node->language][0]['format']  = 'filtered_html';
    // intro text
    $node->field_event_type_intro = $vals->field_event_type_intro;
    // teaser
    $node->teaser = $vals->teaser;
    // data
    $node->data = $vals->data;
    // nodewords
    $node->nodewords = $vals->nodewords;

    $node = node_submit($node); // Prepare node for saving


This seems to be working but when I then click on one of these nodes to edit it it only shows the title in the edit screen. The body and intro are missing.

What am I doing wrong?


1 Answer 1


In your code you have:

$node->field_event_type_intro = $vals->field_event_type_intro;

But if you want to add values to your fields you can use this:

  • if is a text

    $node->field_event_type_intro[LANGUAGE_NONE][0]['value'] = field_event_type_intro;

  • if is a taxonomy

    $node->field_event_type_intro[LANGUAGE_NONE][0]['tid'] = field_event_type_intro;

  • if is a field reference

    $node->field_event_type_intro[LANGUAGE_NONE][0]['target_id'] = field_event_type_intro;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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