Automatically create page in WordPress

前端 未结 2 1473
忘了有多久
忘了有多久 2021-02-01 08:20

How can I automatically create a WordPress page (for example, when plugin is activated)?

2条回答
  •  走了就别回头了
    2021-02-01 09:13

    Use wp_insert_post(), which can insert pages as well: http://codex.wordpress.org/Function_Reference/wp_insert_post

    See post_type below.

    $post = array(
      'ID' => [  ] //Are you updating an existing post?
      'menu_order' => [  ] //If new post is a page, sets the order should it appear in the tabs.
      'page_template' => [