If I update WordPress my custom data will be deleted from the wp_users table? I add new custom field and store data to users at this field if I update WordPress and WordPress needs to update this table my custom field will be deleted?
2 Answers
It is possible, especially if the update includes changes to the user table. The only way to be sure is to test it, but for future reference:
Never modify the scheme of WordPress Tables
If you need to add additional information about something, WordPress provides meta, user meta, site meta, post meta, comment meta. You may know these as custom fields.
For example:
$value = get_user_meta( $user_id, 'example', true );
update_user_meta( $user_id, 'example', 'newvalue' );
$all_meta = get_user_meta( $user_id );
Adding columns manually to tables also bypasses the caching layer slowing things down, encourages writing manual SQL statements ( you could have used the WP_User_Query
class! ), and stops the information being imported/exported ( custom post types get put in content exports, custom tables don't )
I recommend writing a small WP CLI command to fetch each user and store these columns as user meta instead
No, your Custom User Data (i.e. User Meta) will remain safe in database even after you update your WordPress. I've not seen so far the WordPress Updater touching/altering the data in any of the tables.
(Just to keep posted, it's the [prefix]_usermeta
table that holds the user related data; not the [prefix]_users
table.
-
I totally understand you but in my case, i don't add this data as user meta I add this data directly info wp_users I add new field after display_name field and store the data into it, So my question are you sure that if I update WordPress this custom field not be deleted? Thank you for your time.– YoguCommented Jun 22, 2017 at 13:18