Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 使用wp\u insert\u post()创建新页面_Wordpress - Fatal编程技术网

Wordpress 使用wp\u insert\u post()创建新页面

Wordpress 使用wp\u insert\u post()创建新页面,wordpress,Wordpress,我在PHP函数中有以下代码,当我安装允许创建帖子或页面的插件时,会激活该函数 如果$post\u type为“post”,则可以完美地工作并创建页面,但如果$post\u type为“page”,则无法工作,无法创建页面: $my_post = array( 'post_title' => 'My page Reql', 'post_type' => 'page', 'post_name' => 'my-page', 'post_conte

我在PHP函数中有以下代码,当我安装允许创建帖子或页面的插件时,会激活该函数

如果
$post\u type
为“post”,则可以完美地工作并创建页面,但如果
$post\u type
为“page”,则无法工作,无法创建页面:

$my_post = array(
  'post_title'    => 'My page Reql',
  'post_type'     => 'page',
  'post_name'     => 'my-page',
  'post_content'  => 'This is my page reql.',
  'post_status'   => 'publish',
  'comment_status' => 'closed',
  'ping_status' => 'closed',
  'post_author' => 1,
  'menu_order' => 0
);

wp_insert_post( $my_post );
有什么问题?我找不到解决办法


多谢各位

我认为您也必须设置
guid
,如下所示

$PageGuid = site_url() . "/my-page-req1";
$my_post  = array( 'post_title'     => 'My page Reql',
                   'post_type'      => 'page',
                   'post_name'      => 'my-page',
                   'post_content'   => 'This is my page reql.',
                   'post_status'    => 'publish',
                   'comment_status' => 'closed',
                   'ping_status'    => 'closed',
                   'post_author'    => 1,
                   'menu_order'     => 0,
                   'guid'           => $PageGuid );

$PageID = wp_insert_post( $my_post, FALSE ); // Get Post ID - FALSE to return 0 instead of wp_error.

php错误日志中显示了哪些错误?允许用户1发布页面?帖子标题尚未使用?我在我的一个WP安装上测试了它:它工作得很好。我很感激这个
soloution
may
work
但是对我来说这似乎是滥用
guid
字段,为什么你不在
guid
字段中添加一个
guid
?如果有什么我误解了,那么请解释一下,但对于知道guid是什么的人来说,这似乎是一个黑客行为。使用wordpress提供的wp_generate_uuid4()函数不是更好吗?我刚刚尝试了这个有GUID和没有GUID的解决方案。它似乎可以工作,没有这个场景。我建议任何人先尝试没有GUID的解决方案