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');
感謝這幫了我很多 –