How to insert User meta?
See original GitHub issueHi, thank for that library!
I did not really understand the structure of the meta parameter. Could you please give me an example of it?
i’ m trying to insert a new user. I create this function
{
WordPressClient client = await GetClient();
var isValidToken = await client.IsValidJWToken();
if (isValidToken)
{
var newUser = new User("example", "example@example.it", "password")
{
FirstName = "examplename",
LastName = "examplesurname",
NickName = "nick",
Meta = ????
};
Console.WriteLine("Start");
var insUser = await client.Users.Create(newUser);
Console.WriteLine("Done");
}
}
but i don’ t know how insert “Meta”. I must insert that beacuse i use Ultimamate Member plugin and all extra information of a user are insert as meta.
What am i doing wrong?
Thanks for the attenction.
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (2 by maintainers)
Top Results From Across the Web
How to Create and Use WordPress User Metadata ...
The function for either adding or updating WordPress user meta data is called update_user_meta() , and it looks as follows: update_user_meta( $ ...
Read more >Wordpress: Create a new usermeta field for users
You can create a simple plugin to hook into the user profile actions and add a new field. To add the field to...
Read more >How to Add Custom User Profile (User meta) Fields In ...
In the WordPress database, there is a table known as wp_usermeta which stores all extra information that is attached to the user profile....
Read more >Add custom user meta data
global $wpdb; $sql_query = "INSERT INTO {$wpdb->usermeta} (user_id, meta_key, meta_value) " . "SELECT ID, 'YOUR_META_KEY', '' FROM {$wpdb->users ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m also in the same situation, I tried doing something like this but it doesn’t work:
Meta = { meta_field1 = "something1", meta_field2 = "something2" }
Assuming the field names are the ones you can read in the database, how can I structure this meta field correctly?This worked for me:
Create a class with the fields to work with:
Then create an instance of the WordPressPCL.Models.User Class
Populate non-meta fields for example:
Then create an instance of the wpUser.Meta class using the UserMeta class defined above and populate those fields:
This works because the Meta object within the WordPressPCL.Models.User class is defined as dynamic.
Now you can create or update the record (to update define the Id field of the user.)
Hope this helps