Wordpress插件添加新页面

Wordpress插件添加新页面,wordpress,Wordpress,我创建了一个wordpress插件,需要动态创建页面 当插件被激活时,将根据COOKIE\u策略创建一个页面 从我的阅读中,我发现插入数据库是最好的方法。下面是做这件事的方法。但是,当我激活插件时,没有创建任何页面或帖子 我是这样说的: 这个代码几乎是正确的。下面是固定代码 function create_policy() { $my_post = array( 'post_title' => 'cookiepolicy', 'post_content' =>

我创建了一个wordpress插件,需要动态创建页面

当插件被激活时,将根据COOKIE\u策略创建一个页面

从我的阅读中,我发现插入数据库是最好的方法。下面是做这件事的方法。但是,当我激活插件时,没有创建任何页面或帖子

我是这样说的:


这个代码几乎是正确的。下面是固定代码

 function create_policy() {

 $my_post = array(
  'post_title'    => 'cookiepolicy',
  'post_content'  => 'this is my content',
  'post_type'     => 'page',
  'post_status'   => 'publish',
  'post_author'   => 1,
  'post_category' => array( 3,4 )
  );

  // Insert the post into the database
  wp_insert_post( $my_post );
}

register_activation_hook( __FILE__, 'create_policy' );

谢谢,这对我帮助很大
 function create_policy() {

 $my_post = array(
  'post_title'    => 'cookiepolicy',
  'post_content'  => 'this is my content',
  'post_type'     => 'page',
  'post_status'   => 'publish',
  'post_author'   => 1,
  'post_category' => array( 3,4 )
  );

  // Insert the post into the database
  wp_insert_post( $my_post );
}

register_activation_hook( __FILE__, 'create_policy' );