Move WordPress User Meta into Custom Table
Support › MB Custom Table › Move WordPress User Meta into Custom TableResolved
- This topic has 5 replies, 2 voices, and was last updated 3 years, 9 months ago by
Nicholas Cox.
-
AuthorPosts
-
June 15, 2021 at 7:04 PM #28910
Nicholas Cox
ParticipantHi
I am about to create a custom table to store user meta. But I noticed the users 'first_name' and 'last name' exists within the _usermeta database table. Is it possible to alter the way WordPress store this and move it from here into my custom table? or would I just have to ignore this and leave them blank/empty and then add in a first and last name column into my custom table?
I was thinking about when I come to make front end calls to grab the users custom meta, from my custom table, that the only 2 fields I would be missing are the first and last names. Would I have to query the first and last name separately? as I ideally wanted to achieve calling all the users meta in one for loop within my template.
Thanks, hope I'm making sense. Maybe I'm just overthinking the above query.
Nick
June 16, 2021 at 2:09 PM #28931Long Nguyen
ModeratorHi Nicholas,
When editing or creating a user from the frontend, you can follow this documentation to replace the default user first name and last name fields and save data to the custom table https://docs.metabox.io/extensions/mb-user-profile/#edit-default-fields
June 20, 2021 at 4:51 PM #29011Nicholas Cox
ParticipantHi, ok thanks for this, I have created my fields and custom table and used the same ID's e.g. first_name etc and it does store the fields into my custom table correctly.

But I also noticed that it also stores the value into the 'wp_usermeta' table too. Is this correct? Is it supposed to behave like this?

Thanks
June 20, 2021 at 10:32 PM #29016Long Nguyen
ModeratorHi,
If you register the user with the custom fields
first_name,last_nameon the frontend, the field value only saved in the custom table. But if you update the user info in the backend Admin dashboard > Users > Profile, the field value will be saved in both the custom table and the default tablewp_usermetabecausefirst_name,last_nameare two default custom fields of WordPress. Can you please register a new user and re-check it?June 21, 2021 at 5:58 PM #29037Nicholas Cox
ParticipantHi
Ah I was updating those fields in the backend, I have tested this in the front end form now and I can confirm it does not save it to the wp_usermeta table.
Thanks
January 10, 2022 at 10:48 PM #33139Nicholas Cox
ParticipantHi
I have just noticed that whenever a new user or a user updates a profile using metabox forms that the 'first_name' and 'last_name' meta keys are automatically re-added or created under in the database under 'wp_usermeta'. Why is this? is WordPress automatically creating this?
-
AuthorPosts
- You must be logged in to reply to this topic.
