2

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

如果是“发布”,则完美运行并制作页面$post_type,但如果$post_type是“页面”,则它不起作用,不会创建页面。:

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

问题是什么?我找不到解决方案。

非常感谢你!

4

1 回答 1

8

我想你也必须设置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.
于 2012-12-14T06:56:41.373 回答