我开发了一个WordPress插件,它是一个复杂的插件,现在还有什么要做的,我想创建一个属于Page Parent的页面父页面和子页面。
我的页面创建代码如下,第一个函数将创建父页面,第二个函数也是创建父页面,我不能创建第一个页面的子页面,有post_parent但是如何获取id我首先创建的页面父级?
register_activation_hook( __FILE__, 'create_page_1_parent');
function create_page_1_parent()
{
//post status and options
$post = array(
'comment_status' => 'closed',
'ping_status' => 'closed' ,
'post_author' => 1,
'post_date' => date('Y-m-d H:i:s'),
'post_name' => '1first post',
'post_status' => 'publish' ,
'post_title' => 'parent',
'post_type' => 'page',
'post_parent' => '',
'post_content' => '[il_login_form]'
);
//insert page and save the id
$newvalue = wp_insert_post( $post, false );
//save the id in the database
update_option( 'hclpage', $newvalue );
}
register_activation_hook( __FILE__, 'create_page_1_parent_child');
function create_page_1_parent_child()
{
//post status and options
$post = array(
'comment_status' => 'closed',
'ping_status' => 'closed' ,
'post_author' => 1,
'post_date' => date('Y-m-d H:i:s'),
'post_name' => '1first post',
'post_status' => 'publish' ,
'post_title' => 'parent',
'post_type' => 'page',
'post_parent' => '', //what i have to put here that will go udner parent page
'post_content' => '[il_login_form]'
);
//insert page and save the id
$newvalue = wp_insert_post( $post, false );
//save the id in the database
答案 0 :(得分:1)
只需在1个函数中执行两个插入操作。
function create_page_1_parent()
{
//post status and options
$post = array(
'comment_status' => 'closed',
'ping_status' => 'closed' ,
'post_author' => 1,
'post_date' => date('Y-m-d H:i:s'),
'post_name' => '1first post',
'post_status' => 'publish' ,
'post_title' => 'parent',
'post_type' => 'page',
'post_parent' => '',
'post_content' => '[il_login_form]'
);
//insert page and save the id
$newvalue = wp_insert_post( $post, false );
//save the id in the database
update_option( 'hclpage', $newvalue );
//post status and options
$post = array(
'comment_status' => 'closed',
'ping_status' => 'closed' ,
'post_author' => 1,
'post_date' => date('Y-m-d H:i:s'),
'post_name' => '1first post',
'post_status' => 'publish' ,
'post_title' => 'parent',
'post_type' => 'page',
'post_parent' => $newvalue, //what i have to put here that will go udner parent page
'post_content' => '[il_login_form]'
);
//insert page and save the id
$newvalue = wp_insert_post( $post, false );
//save the id in the database
}