2013-01-09 119 views
0

我有一個創建的wordpress插件需要動態創建一個頁面。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'); 

回答

0

此代碼幾乎是正確的。以下是固定代碼

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

感謝這幫了我很多 –