1

can this be simplified into one query using $wpdb->update?

global $wpdb;
$wpdb->update(
    $wpdb->users,
    array('user_login' => $new_user_email),
    array('ID' => $user_id)
);

//Update user nicename
$wpdb->update(
    $wpdb->users,
    array('user_nicename' => $new_user_email),
    array('ID' => $user_id)
);

//Update user display_name
$wpdb->update(
    $wpdb->users,
    array('display_name' => $new_user_email),
    array('ID' => $user_id)
);

With this one , I got error:

Uncaught Error: Call to a member function update() on null

$wpdb->update($wpdb->users,
    array(
        'user_login'    => $new_user_email,
        'user_nicename' => $new_user_email,
        'display_name'  => $new_user_email,
    ), 
    array(
        'ID'    =>  $user_id,
    )
);

Thanks for any feedback.

2
  • Your second block of code is missing global $wpdb;. Is it also missing inyour actual code? Nov 12 at 8:15
  • That's the case, already fixed it. Thank you for @JacobPeattie!
    – wpuser
    Nov 12 at 8:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.