Skip to content

Instantly share code, notes, and snippets.

@tbartels
Forked from mattboon/gist:4045215
Created November 9, 2012 12:04
Show Gist options
  • Save tbartels/4045376 to your computer and use it in GitHub Desktop.
Save tbartels/4045376 to your computer and use it in GitHub Desktop.
Update WP user_login via SQL
<?php
// Force update our username (user_login)
global $wpdb;
// method 1
#$sql = $wpdb->prepare("UPDATE {$wpdb->users} SET user_login = %s WHERE ID = %d", $user_email, $user_id);
#$wpdb->query($sql);
// method 2
$wpdb->update($wpdb->users, array('user_login' => $user_email), array('ID' => $user_id));
@tbartels
Copy link
Author

tbartels commented Nov 9, 2012

You can't use %s for table names or they'll get quoted:

"UPDATE 'wp_users' SET user_login='[email protected]' WHERE ID=1" which would not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment