Last active
          October 11, 2015 08:07 
        
      - 
      
- 
        Save ss81/3828368 to your computer and use it in GitHub Desktop. 
    Creating and Updating Nodes Programmatically in Drupal 7
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <?php | |
| /** | |
| * Basic Node Creation Example for Drupal 7 | |
| * | |
| * This example: | |
| * - Assumes a standard Drupal 7 installation | |
| * - Does not verify that the field values are correct | |
| */ | |
| $body_text = 'This is the body text I want entered with the node.'; | |
| $node = new stdClass(); | |
| $node->type = 'article'; | |
| node_object_prepare($node); | |
| $node->title = 'Node Created Programmatically on ' . date('c'); | |
| $node->language = LANGUAGE_NONE; | |
| $node->body[$node->language][0]['value'] = $body_text; | |
| $node->body[$node->language][0]['summary'] = text_summary($body_text); | |
| $node->body[$node->language][0]['format'] = 'filtered_html'; | |
| $path = 'content/programmatically_created_node_' . date('YmdHis'); | |
| $node->path = array('alias' => $path); | |
| node_save($node); | |
| // (c) http://www.group42.ca/creating_and_updating_nodes_programmatically_in_drupal_7 | |
| // One more: http://timonweb.com/how-programmatically-create-nodes-comments-and-taxonomies-drupal-7 | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment