I am trying to create a new post with tags. Not having any luck and am not able to find any explanations online of what I may be doing wrong.
methods: {
createPost: function() {
let title = this.newPostTitle;
let content = this.newPostContent;
let postCategories = this.postCategories;
let tags = this.newPostTags.split(",");
let data = {
'title': title,
'content': content,
'status': 'publish',
'categories': postCategories,
'tags': tags,
};
axios.post("/wp-json/wp/v2/posts/", data, {headers: {'X-WP-Nonce': portal.nonce}})
.then(response => {
console.log(response);
})
.catch(e => {
this.errors.push(e);
console.log(this.errors);
});
this.newPostTitle = '';
this.newPostContent = '';
this.newPostTags = '';
this.postCategories = false;
}
}
I have the method property above to get the data and post it using VueJS and Axios. What do i need to do to get the tags to post correctly?
I keep getting the following error when I attempt to post
"tags[0] is not of type integer."
split
returns an array of strings, even if those strings are numbers. instead of split try something like this: