简体   繁体   中英

Unable to insert value in the newly column added in the wp-user

I have added a new column in wp-user named as twitter_username and its datatype is varchar. In sign up form I have also added a new field named as twitter username. when I signup, I am unable to save that field's value in "twitter_username" column in wp-user table. i have tried following code all values are storing in the wp-user table instead of the "twitter_username".

$new_customer_data = apply_filters('woocommerce_new_customer_data', array(
        'user_login' => $username,
        'user_pass' => $password,
        'user_email' => $email,
        'twitter_username' => $twitter_username,
        'role' => 'customer',
        'user_url' => 'this is url'
    ));

    $customer_id = wp_insert_user($new_customer_data);

if you can store this twitter_username in usermeta try this code. update_user_meta( $user_id, 'twitter_username', $twitter_username);

This could work for you

$new_customer_data  = array(
     'user_login' => $username,
    'user_pass' => $password,
    'user_email' => $email,
    'role' => 'customer',
);

//Using WP inbuilt function to create users
$user = wp_insert_user($new_customer_data);

//Adding additional data in user meta
add_user_meta($user, 'twitter_username', $twitter_username);
$new_customer_data = apply_filters_ref_array('woocommerce_new_customer_data', array(
'user_login' => $username,
'user_pass' => $password,
'user_email' => $email,
'twitter_username' => $twitter_username,
'role' => 'customer',
'user_url' => 'this is url'
));

$customer_id = wp_insert_user($new_customer_data);

//On success
if ( ! is_wp_error($customer_id ) ) {
echo "User created : ".  $customer_id;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM