I’m trying to add new post with thumb image but i still couldnt get success on it.
public static int addContent(int postType, string title, string body, string post_thumbnail, string[] categories, string[] tags, DateTime dateCreated)
{
Post post = setPost(postType, title, body, post_thumbnail, categories, tags, dateCreated);
using (var wrapper = getWordPressWrapper())
{
return wrapper.NewPost(post, true);
}
}
get setPost method,
public static Post setPost(int postType, string title, string body, string post_thumbnail, string[] categories, string[] tags, DateTime dateCreated)
{
string type = postType == 1 ? "post" : "page";
var customFields = new CustomField[] {
new CustomField() {
// Don't pass in ID. It's auto assigned for new custom fields.
// ID = "name",
Key = "post_thumbnail",
Value = post_thumbnail
}
//,
// new CustomField() {
// // Don't pass in ID. It's auto assigned for new custom fields.
// // ID = "name",
// Key = "post-thumbnail",
// Value = post_thumbnail
//} ,
// new CustomField() {
// // Don't pass in ID. It's auto assigned for new custom fields.
// // ID = "name",
// Key = "post-thumbnails",
// Value = post_thumbnail
//} ,
// new CustomField() {
// // Don't pass in ID. It's auto assigned for new custom fields.
// // ID = "name",
// Key = "thumbnail",
// Value = post_thumbnail
//}
};
return new Post
{
PostType = type,
Title = title,
Body = body,
Categories = categories,
Tags = tags,
DateCreated = dateCreated,
CustomFields = customFields
};
}
as you see its commented. I tried everything to post thumb images.
I’ve tried post_thumbnail, post-thumbnail, post-thumbnails, thumbnail keys but nothing happen.
How can i do that?
Assuming the thumbnail is already uploaded, and you know its media id,
should work.