如何以编程方式在WordPress中创建帖子

时间:2013-01-30 14:03:52

标签: php html wordpress

我想知道我是如何以编程方式为大约七个不同的帖子在WordPress中创建帖子的?

我试过了:

 <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>

它没有显示任何内容?

1 个答案:

答案 0 :(得分:11)

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);