我正在尝试用拇指图片添加新帖子,但我仍然无法获得成功。
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);
}
}
获取setPost方法,
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
};
}
正如您所看到的那样评论。我尝试了一切来发布拇指图像。
我尝试了post_thumbnail,缩略图后,缩略图后缩略图,缩略图键,但没有任何结果。
我该怎么做?
答案 0 :(得分:0)
假设缩略图已上传,并且您知道其媒体ID,
Key = "_thumbnail_id",
Value = id_of_uploaded_thumbnail
应该有用。