Support » Plugins » Insert foreign key to create User

  • Good afternoon everyone. I am creating a form to MANAGER , which filled automatically creates a user (subscriber ) with those data. But I need time to create a user , the Manager ID, ​​go to foreign key wp- user table. I can do most , however the foreign key does not receive the value Manager ID , is to 0. It sure is why I created this separate field , then it is not a standard field that wp- user table. My code below:

    // inicio do cadastrar gestor
    $cons = $pdo->prepare(“INSERT INTO cad_gestores(nome_gestor, email_gestor, ID) VALUES (?,?,?)”);
    $cons->bindValue(1, $nome);
    $cons->bindValue(2, $email);
    $cons->bindValue(3, $id_user);
    // fim do cadastrar gestor

    // seleciono o ID do gestor criado acima
    $lastid = $pdo->lastInsertId(‘id_gestor’);

    $senha = wp_generate_password($length=12, $include_standard_special_chars=false);

    // array para criar o usuário com os dados do Gestor preenchido acima
    $user_info = array(
    “user_pass” => $senha,
    “user_login” => $nome,
    “user_email” => $email,
    “display_name” => $nome,
    “id_gestor” => $lastid /* Here I need to get the value of gestor id */
    $insert_user_result = wp_insert_user( $user_info );

    This user has a table id_gestor , need foreign key that receives the key MANAGER ID is the primary key .

    I thank you guys .

  • The topic ‘Insert foreign key to create User’ is closed to new replies.