这是行动挂钩user_register 将用户添加到数据库后立即调用。用户id作为参数传递给挂钩。
您可以使用wp_insert_post 在该操作中插入新帖子。你只需要从用户那里获取相关信息并将其添加到帖子中。您可以通过引用返回的帖子ID向创建的帖子添加自定义字段wp_insert_post.
这是一个如何在用户注册时添加自定义帖子类型帖子的示例-您显然需要更改它以满足您的需要,但它应该让您知道该怎么做。
/*
* Create new custom post type post on new user registration
*/
add_action( \'user_register\', \'wpse_216921_company_cpt\', 10, 1 );
function wpse_216921_company_cpt( $user_id )
{
// Get user info
$user_info = get_userdata( $user_id );
// Create a new post
$user_post = array(
\'post_title\' => $user_info->nickname;
\'post_content\' => $user_info->description,
\'post_type\' => \'your_company_custom_post_type\', // <- change to your cpt
);
// Insert the post into the database
$post_id = wp_insert_post( $user_post );
// Add custom company info as custom fields
add_post_meta( $post_id, \'company_id\', $user_info->ID );
add_post_meta( $post_id, \'company_email\', $user_info->user_email );
}