Skip to content

Instantly share code, notes, and snippets.

@rintoug
Last active June 11, 2017 06:06
Show Gist options
  • Save rintoug/c7c2ce14b467c4d9f4260d27b911c658 to your computer and use it in GitHub Desktop.
Save rintoug/c7c2ce14b467c4d9f4260d27b911c658 to your computer and use it in GitHub Desktop.
Insert a post programatically in wordpress
<?php
$slug = 'your-post-slug';
$title= 'Your post title';
$post_content = 'Your lonng post title';
$post_id = wp_insert_post(
array(
'comment_status' => 'closed',
'ping_status' => 'closed',
'post_author' => $author_id,
'post_name' => $slug,
'post_title' => $title,
'post_status' => 'publish',
'post_type' => 'post',
'post_content' => $post_content,
'post_category' => array(1), //give your category id
)
);
print $post_id; //will print the inserted post's id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment