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.
Any idea?
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.
Any idea?
Share Improve this question asked Jun 22, 2017 at 1:15 YoguYogu 855 silver badges14 bronze badges 1 |2 Answers
Reset to default 1You cannot add a field
to the database table. You can only add a row
or column
, and neither are supposed to be added directly to the database, especially column
!
With 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.
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.
https://github/CMB2/CMB2
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744851720a4597163.html
wp_usermeta
or to create another table all together if that doesn't suffice. – NightHawk Commented May 7, 2018 at 21:48