你已经自己回答了这个问题,
创建一个将创建3个帖子的函数,例如:
function create_new_user_posts($user_id){
if (!$user_id>0)
return;
//here we know the user has been created so to create
//3 posts we call wp_insert_post 3 times.
// Create post object
$my_bio_post = array(
\'post_title\' => \'bio\',
\'post_content\' => \'This is my post.\',
\'post_status\' => \'publish\',
\'post_author\' => $user_id
);
// Insert the post into the database
$bio = wp_insert_post( $my_bio_post );
$my_portfolio_post = array(
\'post_title\' => \'portfolio\',
\'post_content\' => \'This is my post.\',
\'post_status\' => \'publish\',
\'post_author\' => $user_id
);
// Insert the post into the database
$portfolio = wp_insert_post( $my_portfolio_post );
$my_contact_post = array(
\'post_title\' => \'bio\',
\'post_content\' => \'This is my post.\',
\'post_status\' => \'publish\',
\'post_author\' => $user_id
);
// Insert the post into the database
$contact = wp_insert_post( $my_contact_post );
//and if you want to store the post ids in
//the user meta then simply use update_user_meta
update_user_meta($user_id,\'_bio_post\',$bio);
update_user_meta($user_id,\'_portfolio_post\',$portfolio);
update_user_meta($user_id,\'_contact_post\',$contact);
}
然后使用
user_register 钩
add_action(\'user_register\',\'create_new_user_posts\');
Update当您将函数挂接到
user_register 该函数接收用户id,以便您可以使用该id获取有关该用户的任何信息,例如:
$user = get_user_by(\'id\', $user_id);
现在$user是一个用户对象,因此您可以将帖子标题更改为user用户信息,例如:
\'post_title\' => $user->user_firstname . " ". $user->user_lastname . \'bio\'