There times when you want to add post from your code. For example for creating a custom post panel for your users in a classifieds site. But most of them don't know that this can be achieved very easily. Just paste the following code anywhere on WordPress theme files. If you want to test,But for testing pasting it in your 'functions.php' file is recommended.
That's all you have to do. Once executed, this code will insert a new post into WordPress database.
Related Posts:
Add Categories & Tags programmatically to WordPress
Insert Custom Content After Each Post
global $user_ID;
$new_post = array(
'post_title' => 'My New Post',
'post_content' => 'Lorem ipsum dolor sit amet...',
'post_status' => 'publish',
'post_date' => date('Y-m-d H:i:s'),
'post_author' => $user_ID,
'post_type' => 'post',
'post_category' => array(0)
);
$post_id = wp_insert_post($new_post);
That's all you have to do. Once executed, this code will insert a new post into WordPress database.
Related Posts:
Add Categories & Tags programmatically to WordPress
Insert Custom Content After Each Post
Comments
Post a Comment