WordPressSharp icon indicating copy to clipboard operation
WordPressSharp copied to clipboard

save post with featureImage not working

Open alikianinejad opened this issue 5 years ago • 2 comments

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

alikianinejad avatar Jul 17 '18 04:07 alikianinejad

Please use the same post send request to complete the upload process。 For example CreateFromUrl(Post post,stirng ImgUrl)

Blackcat156 avatar Jul 27 '18 03:07 Blackcat156

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.

Blackcat156 avatar Oct 29 '18 06:10 Blackcat156