【问题标题】:Wordpress Plugin Add New PageWordpress 插件添加新页面
【发布时间】:2013-01-09 10:53:36
【问题描述】:

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

当插件被激活时,会创建一个 COOKIE_POLICY 页面。

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

我来自: http://codex.wordpress.org/Function_Reference/wp_insert_post

function create_policy() {

  $my_post = array(
  'post_title'    => wp_strip_all_tags( $_POST['COOKIE_POLICY'] ),
  'post_content'  => $_POST['Here is all our cookie policy info'],
  'post_status'   => 'publish',
  'post_author'   => 1,
  'post_category' => array( 8,30 )
  );

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

register_activation_hook( __FILE__, 'create_policy' );

【问题讨论】:

    标签: wordpress


    【解决方案1】:

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

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

    【讨论】:

    • 感谢这对我帮助很大
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多