Last active
June 11, 2017 06:06
-
-
Save rintoug/c7c2ce14b467c4d9f4260d27b911c658 to your computer and use it in GitHub Desktop.
Insert a post programatically in wordpress
This file contains 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 | |
$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