Добавление поста с миниатюрой изображения в блог Wordpress с JoeBlogs / C#

Я пытаюсь добавить новое сообщение с изображением большого пальца, но все еще не могу добиться успеха.

 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, post-thumbnail, post-thumbnails, thumbnail keys, но ничего не произошло.

Как я могу это сделать?

1 ответ

Предполагая, что эскиз уже загружен, и вы знаете его медиа-идентификатор,

Key = "_thumbnail_id", 
Value = id_of_uploaded_thumbnail

должно сработать.

Другие вопросы по тегам