WordPressSharp
WordPressSharp copied to clipboard
save post with featureImage not working
i am trying to save new post with thumbnail in wordpress database with following code
var img_url = SourceURL.Text + "/files/images/thumb/400_" + data.my_post.thumbnail;
var featureImage = Data.CreateFromUrl(img_url);
var img = data.client.UploadFile(featureImage);
post.FeaturedImageId = img.Id;
post.Id = data.client.NewPost(post);
and after that with checking database i see the new post and attachment and file upload successfully in wp-content/uploads but in attachment record parent_post set to 0 instead of new post id and thumbnail field is empty in wordpress how can i fix that i check blow links How to add thumbnail image into newPost #44 Featured Images & Custom Fields #64
Please use the same post send request to complete the upload process。 For example CreateFromUrl(Post post,stirng ImgUrl)
I have the same problem with you today. The solution is as follows: UploadResult img = client.UploadFile(WordPressSharp.Models.Data.CreateFromUrl(item, "image/jpeg")); If no file type is set,The default file type is: application/octet-stream It can't be set as a cover picture. So set the parameter: image/jpeg You can solve the problem.