WP-API Term/Taxonomy Support
This is a simple plugin that lets you add terms when you POST new content to the WP REST API.
Here's an example of a JSON post object (POSTed to /wp-json/posts
) that will create a new post with some tags:
{
"title": "Hello there",
"content_raw": "My awesome content",
"x-terms": [{
"post_tag": {
"terms": [
"my_tag",
"my_other_tag"
]
}
}]
}
and a custom taxonomy:
{
"title": "Hello there",
"content_raw": "My awesome content",
"x-terms": [{
"my_taxonomy": {
"terms": [
"my_term"
]
}
}]
}
and both at the same time:
{
"title": "Hello there",
"content_raw": "My awesome content",
"x-terms": [{
"post_tag": {
"terms": [
"my_tag",
"my_other_tag"
]
},
"my_taxonomy": {
"terms": [
"my_term"
]
}
}]
}
By default, this will overwrite existing terms on a post (within the taxonomy you're working with). To only append content, use the "append" setting:
{
"title": "Hello there",
"content_raw": "My awesome content",
"x-terms": [{
"post_tag": {
"append": "true",
"terms": [
"my_appended_tag"
]
}
}]
}
I'm indebted to WordPress.org user WizADSL who created the original version of this plugin for categories and tags.
License
GPLv2 or later. Enjoy!