Closed eBenassati closed 4 years ago
Is this still an issue?
Yes, I created the same issue before this one per https://github.com/wp-net/WordPressPCL/issues/160
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?
@ThomasPe, this is still an issue. Would you please review and provide us your feedback? Thank you.
I'm having the same Problem :/ Did someone find a solution for it ?
@hbcondo I found a solution for it, what you need to do is to set up the register_meta in your "function.php". And then just simply do it like i did it in the Image
I hope i could help you.
@hbcondo @LSparkzwz @eBenassati did this solution work for you?
Is there a way to add / edit user meta data using only WordPressPCL?
This worked for me:
Create a class with the fields to work with:
public class UserMeta
{
public string _full_name { get; set; }
public string _company_name { get; set; }
public string _company_website { get; set; }
}
Then create an instance of the WordPressPCL.Models.User Class
var wpUser = new WordPressPCL.ModelsUser();
Populate non-meta fields for example:
wpUser.Email = Input.Email;
wpUser.FirstName = Input.FirstName;
Then create an instance of the wpUser.Meta class using the UserMeta class defined above and populate those fields:
wpUser.Meta = new UserMeta()
{
_company_name = Input.CompanyName,
_company_website = Input.CompanyWebsite,
_full_name = Input.FirstName + " " + Input.LastName
};
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.)
User wpRespond = new User();
try
{
client.JsonSerializerSettings = new JsonSerializerSettings() { DefaultValueHandling = DefaultValueHandling.Ignore };
wpRespond = await client.Users.Create(wpUser);
}
catch (WPException wpex)
{
//var name = wpex.BadRequest.Name;
//var message = wpex.BadRequest.Message
//var wpex.BadRequest.Data
throw wpex;
};
Hope this helps
Hi i tried @carlford10s solution but it doesnt work for me. Has something changed since 2020?
Hi, 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
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.