Drupal 7 Create node with node_add() in custom module

12 years ago, May 2, 2012
Reading time: 1 mins

<code>$node = new stdClass();
    $node->type = 'my_content_type';
    $node->format = 3;
    $node->status = 1;
    $node->uid = 2;
    $node->name = 'User_name';
    
    $node->title = "Test title";
    $node->body['und'][0]['value'] = "Body text";
    
    $node->field_taxonomy_field['und'][0]= array('tid' => 51); //51 is the term id
   
    node_object_prepare($node);
    
    $node->language = 'en';  
      
    $node->is_new = true;  
    $node = node_submit($node);
    $node_id =  node_save($node);</code>

Previous
Worldlink (wlink) is the worst ISP of Nepal
Next
latency of the NTCs ADSL gateway from my home so high often request times out.
© 2024 Anil Maharjan