php - How to add data to a custom field at the wp_users table?

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

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
  • 3 You don't want to modify the existing WordPress tables, because there is no guarantee that WordPress won't change something in the future that will completely collide with what you're doing. The correct way is, in fact, to store meta data in wp_usermeta or to create another table all together if that doesn't suffice. – NightHawk Commented May 7, 2018 at 21:48
Add a comment  | 

2 Answers 2

Reset to default 1

You 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

相关推荐

  • php - How to add data to a custom field at the wp_users table?

    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

    2天前
    80

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信