How to add data to a custom field at the wp_users table?
I already add a new field to the wp_users table but I don't know how to add the data to this field I want to use something like add_user_meta.
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.Sign up to join this community
You're correct in using the add_user_meta() function. You can use it to pass the field name, value and the user id it is to be associated with.
Another option, if you are creating a meta box for custom information on the user profile page would be to use an existing library. Something like CMB2 will handle this really well.
You cannot add a
field to the database table. You can only add a
column, and neither are supposed to be added directly to the database, especially
add_user_meta you are adding a new
row but to the
wp_usermeta table, and that should be sufficient for any extra required fields. This table is meant to be used for extending the user's profile with any amount of custom data, since it is
key => value structured.
Again, if you add any
column to the
wp_users table, you can't access this data using native WordPress functions. You can only get it by writing a custom SQL query, but I don't think you actually need this.