wp-net / WordPressPCL

This is a portable library for consuimg the WordPress REST-API in (almost) any C# application
MIT License
342 stars 130 forks source link

Featured Media is deleted if the post is updated without specifying a value for it #126

Closed sinmax01 closed 6 years ago

sinmax01 commented 6 years ago

If I create a new Post object, set the field values I want to be updated (but not the FeaturedMedia field) and then call the Update method, the featured_media in JSON is set to 0, so the previous Featured Media of the post is deleted. As a work-around, I created a new class, MyPost that inherited Post, and override the property FeaturedMedia: [JsonProperty("featured_media", NullValueHandling = NullValueHandling.Ignore)] public new int? FeaturedMedia { get; set; } This way, as the FeaturedMedia is not sent to the REST API, it is not replaced in WordPress, but the old value before the update request is kept. I think this property should replace the FeaturedMedia property in the Post class. And if there are other cases like this one, I think they should also be replaced.

ThomasPe commented 6 years ago

I think it's reasonable to expect a missing featured_media id not to be replaced by a 0. Would you care to submit this as a PR?

sinmax01 commented 6 years ago

I did not get to reply to this issue, but now I found that polushinmk solved it. Thanks!