我得到这个错误
Fatal error: Call to a member function get_page_permastruct() on a non-object in C:\\xampp\\htdocs\\wordpress\\wp-includes\\link-template.php on line 358
当我调用此函数时
function pn_create_page() {
global $wpdb;
$check_page = $wpdb->get_var("SELECT option_value FROM ".$wpdb->prefix."pn_options WHERE id = \'10\'" );
// if no page create one
if ($check_page==\'\'){
$pagedata = array(
\'post_content\' => \'Page content will go here.\',
\'post_title\' => \'Page Title\',
\'post_status\' => \'publish\',
\'post_type\' => \'page\',
\'post_author\' => 1,
\'ping_status\' => \'closed\',
\'comment_status\' => \'closed\'
);
$post_id = wp_insert_post( $pagedata );
$wpdb->update($wpdb->prefix.\'pn_options\', array(\'option_value\'=>$post_id), array(\'id\'=>\'10\'));
// if page excist do nothing
} else {
return;
}
}
导致错误的线是
$post_id = wp_insert_post( $pagedata );
我也收到了这个通知
Notice: Trying to get property of non-object in C:\\xampp\\htdocs\\wordpress\\wp-includes\\post.php on line 3688
来自同一行。。。。。
不知道怎么了。。。。有什么想法吗?
我想直接从插件创建wordpress页面。。。。