当用户在自定义帖子类型中注册时,以下代码会自动为其创建新帖子(jt_cpt_team
) 对于团队成员。
拼图中最后缺失的部分是保存$user_id
在custom\\u字段中(jt_user_id
) 在新创建的帖子中。
关于如何实现这一点,有什么想法吗?提前感谢您的帮助。
class team_functions {
public function __construct() {
add_action(\'user_register\', array($this, \'create_authors_page\'), 999);
}
public function create_authors_page( $user_id ) {
$the_user = get_userdata( $user_id );
$new_user_name = $the_user->user_login;
$fname = $the_user->first_name;
$lname = $the_user->last_name;
$PostSlug = $user_id;
$PostGuid = home_url() . "/" . $PostSlug;
$my_post = array( \'post_title\' => $fname . \'\' . $lname,
\'post_type\' => \'jt_cpt_team\',
\'post_content\' => \'\',
\'post_status\' => \'publish\',
\'post_theme\' => \'user-profile\',
\'guid\' => $PostGuid );
$NewPostID = wp_insert_post( $my_post ); // Second parameter defaults to FALSE to return 0 instead of wp_error.
$key = \'jt_user_id\'; // Custom Field Key
$Value = $user_id; // User ID is the custom_field value
update_post_meta( $NewPostID, $Key, $Value );
return $NewPostID;
}
}
道具到
Felipe 让我走了这么远顺便说一下:)