In WordPress I can use wp_insert_post() to create content programatically.

Is there any similar function available for Drupal 7, that will allow me to insert posts (and pages) into the database programatically?

  • Hope you don't mind, I changed the wording of the question a bit to make it potentially more useful and easier to find for others coming from a wordpress background
    – Clive
    Commented Apr 6, 2013 at 15:44

1 Answer 1


you can create a custom function to create a node.

function create_my_node() {
  $node = new stdClass();
  $node->type = 'your content type';

  $node->title = "your title";
  $node->language = LANGUAGE_NONE;
  global $user;

  $newnode->uid = $user->uid;
  $newnode->name = $user->name;
  $newnode->status = 1;     // 1 means published
  $newnode->promote = 0;
  • thanks for that,, pls give me some reference if possible..
    – rakibtg
    Commented Apr 6, 2013 at 11:15
  • Here you go.
    – nit3ch
    Commented Apr 6, 2013 at 11:18

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.