Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Create a Post in WordPress Programmatically [closed]

I would like to know how I create posts in WordPress programmatically for around seven different posts?

I tried:

 <div class="demo">     
<?php 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); ?>
</div>

It did not display anything?

like image 961
user1438026 Avatar asked Jan 30 '13 14:01

user1438026


1 Answers

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);
like image 183
Sankalp Mishra Avatar answered Oct 19 '22 17:10

Sankalp Mishra