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

Php 如何以编程方式在WordPress中创建帖子,php,html,wordpress,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

我想知道我是如何在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>


它没有显示任何内容

WP文档没有我想要的那么完整,但是像这样简单的东西可以很容易地搜索到。在提问之前,请始终进行彻底的搜索-这将使您成为一名更加自给自足的程序员。@yan.kun实际上这不是我要寻找的。我尝试了所有方法,但都没有奏效。那么您尝试了什么?如果我们在stackoverflow上不知道您到目前为止做了什么,我们将无法帮助您。不,
wp\u insert\u post()
调用不会显示任何内容-这将以编程方式在wp中创建一篇文章,这正是您所要求的。如果你刷新你的博客,它将显示新文章。但是,如果遇到插入错误,请检查函数的返回值。它没有显示任何内容?不,wp_insert_post()调用不会显示任何内容-这会以编程方式在wp中创建一个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);