wp-net / WordPressPCL

This is a portable library for consuimg the WordPress REST-API in (almost) any C# application
MIT License
338 stars 129 forks source link

Can't create a post with category #153

Closed d668 closed 5 years ago

d668 commented 5 years ago
  var post = new Post
            {
                Title = new Title { Raw = blogPost.Title },
                Content = new Content { Raw = "blah..." },
                Status = Status.Publish,
                Categories = new int[3],
            };
            var result = Client.Posts.Create(post).Result;

throws Sorry, you are not allowed to assign the provided terms. Categories = new int[0] works fine. There is a category with id = 3 for sure, I can see it if I do

var categorries = Client.Categories.Get().Result;
var categorryId = categorries.FirstOrDefault(x => x.Name == "My Category")?.Id;

result is 3

polushinmk commented 5 years ago

Hi @intergleam ! Seems that mistake is there Categories = new int[3] new int[3] means empty int array with length of 3 if you want to create an int array with item 3 you should use these code new int[] { 3 }

d668 commented 5 years ago

wow, thanks!