我正在尝试通过编程方式向WordPress添加页面。我正在使用此代码:
function add_media_page(){
if(!(is_page(\'My New Post\'))){
// Create post object
$my_post = array(
\'post_title\' => \'My new Post\',
\'post_content\' => \'This is my post.\',
\'post_status\' => \'publish\',
\'post_author\' => 1,
\'post_type\' => [\'page\']
);
// Insert the post into the database
wp_insert_post( $my_post );
}
}
add_action( \'init\', \'add_media_page\' );
但是,当我使用数组“post\\u type”=>[“page”]中的最后一行时,它会导致管理员崩溃并显示一个空白页面。有人知道这里发生了什么吗
SO网友:markratledge
在函数中的代码中尝试此操作。php
global $user_ID;
$new_post = array(
\'post_title\' => \'My New Post\',
\'post_content\' => \'Lorem ipsum dolor sit amet...\',
\'post_status\' => \'publish\',
\'post_date\' => date(\'Y-m-d H:i:s\'),
\'post_author\' => $user_ID,
\'post_type\' => \'post\',
\'post_category\' => array(0)
);
$post_id = wp_insert_post($new_post);