Closed AntonStein closed 6 years ago
Have you taken a look at the wiki here? https://github.com/wp-net/WordPressPCL/wiki/Working-with-Posts#create-new-post Have you authenticated the client?
I'll see if I can add a test to reproduce this.
Thanks for your answer. I've found my issue..
I was kinda unfocused, sorry :/...
Here is the solution:
Tag curTag = new Tag("name");
curTag.Description = "JobID";
var createdTag = Client.Tags.Create(curTag).Result;
Client.Posts.Create(CreateNewPost(job, createdTag)).Wait();
private static Post CreateNewPost(Job job, Tag tag)
{
WordPressPCL.Models.Post _post = new Post()
{
Title = new Title(job.Offer.Title),
Content = new Content(job.Offer.Html),
Date = ParseDate(job.Offer.Publication.Start),
Tags = new int[] { tag.Id }
};
return _post;
}
I'm trying to do a very similar code, to insert Tags. However I have a list with an array of tags. Like this:
List<Tag> t = new List<Tag>();
string sTag = textBoxTags.Text;
// Split string on commas
string[] words = sTag.Split(',');
foreach (string word in words)
{
t.Add(new Tag { Name = word.ToString(), Description = "Tag" });
}
My issue is if the tag already exist give error. I already tried many approaches without success. Anyone can help, please?
Tag curTag = new Tag("name"); curTag.Description = "JobID"; var createdTag = Client.Tags.Create(curTag).Result;
Client.Posts.Create(CreateNewPost(job, createdTag)).Wait();
private static Post CreateNewPost(Job job, Tag tag) { WordPressPCL.Models.Post _post = new Post() { Title = new Title(job.Offer.Title), Content = new Content(job.Offer.Html), Date = ParseDate(job.Offer.Publication.Start), Tags = new int[] { tag.Id } }; return _post; }
Always when i try to create a Tag i get an Exception "Du bist leider nicht berechtigt, die angegebenen Begriffe zuzuordnen." although the tag was created in wordpress. Is that a bug or am i doin something wrong?!
EDIT: I've just noticed, that the Exception is thrown when i try to create a post with the Tag I've created before.
Any Idea what's wrong there?
with best regards
Anton