Tags

These routes allow you to get/create/update/delete tags.

Possible routes (endpoints are described below):

/wp/v2/tags         // works with all tags
/wp/v2/tags/{ID}    // works with the specified tag instead of {ID}

Controller class: WP_REST_Terms_Controller{}

Resource Schema

The schema shows all fields that exist for the object: the object fields that the request will return.

Parameter Context Description
id
number
view, edit, embed Term ID (tag).
Read-only.
count
number
view, edit Number of records in the term (tag).
Read-only.
description
string
view, edit Description of the term (tag).
link
string, uri
view, edit, embed URL of the term (tag).
Read-only.
name
string
view, edit, embed Name of the term (tag).
slug
string
view, edit, embed Slug of the term (tag), usually created from the name.
taxonomy
string
view, edit, embed Name of the taxonomy.
Read-only.
Can be: category, post_tag, nav_menu, link_category, post_format
parent
number
view, edit ID of the parent term.
meta
object
view, edit Meta fields.

Context — shows which object fields will be returned in the response when creating a request in the specified context. For example, when updating or creating a category, fields corresponding to the context edit will be returned.

wp/v2/tags

An OPTIONS request to the route will return a complete description of this route: endpoints, their parameters, schema.

$ curl -X OPTIONS -i http://demo.wp-api.org/wp-json/wp/v2/tags
GitHub
{
    "namespace": "wp/v2",
    "methods": [
        "GET",
        "POST"
    ],
    "endpoints": [
        {
            "methods": [
                "GET"
            ],
            "args": {
                "context": {
                    "required": false,
                    "default": "view",
                    "enum": [
                        "view",
                        "embed",
                        "edit"
                    ],
                    "description": "Рамки в которых сделан запрос, определяют поля в ответе.",
                    "type": "string"
                },
                "page": {
                    "required": false,
                    "default": 1,
                    "description": "Текущая страница коллекции.",
                    "type": "integer"
                },
                "per_page": {
                    "required": false,
                    "default": 10,
                    "description": "Максимальное число объектов возвращаемое в выборке.",
                    "type": "integer"
                },
                "search": {
                    "required": false,
                    "description": "Ограничить результаты до совпадающих со строкой.",
                    "type": "string"
                },
                "exclude": {
                    "required": false,
                    "default": [],
                    "description": "Убедиться что выборка исключает определенные ID.",
                    "type": "array",
                    "items": {
                        "type": "integer"
                    }
                },
                "include": {
                    "required": false,
                    "default": [],
                    "description": "Ограничить выборку до определенных ID.",
                    "type": "array",
                    "items": {
                        "type": "integer"
                    }
                },
                "offset": {
                    "required": false,
                    "description": "Сдвиг выборки на определенное число объектов.",
                    "type": "integer"
                },
                "order": {
                    "required": false,
                    "default": "asc",
                    "enum": [
                        "asc",
                        "desc"
                    ],
                    "description": "Упорядочить сортировку атрибута по возрастанию или убыванию.",
                    "type": "string"
                },
                "orderby": {
                    "required": false,
                    "default": "name",
                    "enum": [
                        "id",
                        "include",
                        "name",
                        "slug",
                        "include_slugs",
                        "term_group",
                        "description",
                        "count"
                    ],
                    "description": "Сортировать коллекцию по атрибутам элемента.",
                    "type": "string"
                },
                "hide_empty": {
                    "required": false,
                    "default": false,
                    "description": "Скрывать ли элементы не назначенные ни одной записи.",
                    "type": "boolean"
                },
                "post": {
                    "required": false,
                    "description": "Ограничить выборку элементами назначенными определенной записи.",
                    "type": "integer"
                },
                "slug": {
                    "required": false,
                    "description": "Ограничить выборку элементами с одним или более специальными ярлыками. ",
                    "type": "array",
                    "items": {
                        "type": "string"
                    }
                }
            }
        },
        {
            "methods": [
                "POST"
            ],
            "args": {
                "description": {
                    "required": false,
                    "description": "HTML описание элемента.",
                    "type": "string"
                },
                "name": {
                    "required": true,
                    "description": "HTML название элемента.",
                    "type": "string"
                },
                "slug": {
                    "required": false,
                    "description": "Буквенно-цифровой идентификатор элемента уникальный для его типа.",
                    "type": "string"
                },
                "meta": {
                    "required": false,
                    "description": "Мета поля.",
                    "type": "object"
                }
            }
        }
    ],
    "schema": {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "title": "tag",
        "type": "object",
        "properties": {
            "id": {
                "description": "Уникальный идентификатор элемента.",
                "type": "integer",
                "context": [
                    "view",
                    "embed",
                    "edit"
                ],
                "readonly": true
            },
            "count": {
                "description": "Число опубликованных записей элемента.",
                "type": "integer",
                "context": [
                    "view",
                    "edit"
                ],
                "readonly": true
            },
            "description": {
                "description": "HTML описание элемента.",
                "type": "string",
                "context": [
                    "view",
                    "edit"
                ]
            },
            "link": {
                "description": "URL элемента.",
                "type": "string",
                "format": "uri",
                "context": [
                    "view",
                    "embed",
                    "edit"
                ],
                "readonly": true
            },
            "name": {
                "description": "HTML название элемента.",
                "type": "string",
                "context": [
                    "view",
                    "embed",
                    "edit"
                ],
                "required": true
            },
            "slug": {
                "description": "Буквенно-цифровой идентификатор элемента уникальный для его типа.",
                "type": "string",
                "context": [
                    "view",
                    "embed",
                    "edit"
                ]
            },
            "taxonomy": {
                "description": "Тип атрибуции элемента.",
                "type": "string",
                "enum": [
                    "category",
                    "post_tag",
                    "nav_menu",
                    "link_category",
                    "post_format"
                ],
                "context": [
                    "view",
                    "embed",
                    "edit"
                ],
                "readonly": true
            },
            "meta": {
                "description": "Мета поля.",
                "type": "object",
                "context": [
                    "view",
                    "edit"
                ],
                "properties": []
            }
        }
    },
    "_links": {
        "self": "http://wptest.ru/wp-json/wp/v2/tags"
    }
}

List of Tags

Gets a list of tags, similar to get_tags().

Request Type

GET /wp/v2/tags

Request Parameters

context
The area in which the request is made; defines the fields present in the response.
Can be: view, embed, edit
Default: view
page
Current pagination page.
Default: 1
per_page
Maximum number of items returned in the result.
Default: 10
search
Limit results to those matching the string.
exclude
Excludes tags by ID.
include
Shows only the specified tags. ID is provided.
orderby
Which field to sort by?
Can be: id, include, name, slug, term_group, description, count
Default: name
order
How to sort?
Can be: asc, desc
Default: asc
hide_empty
Hide empty tags (where there are no posts)?
parent
ID of the parent tag whose children need to be retrieved.
post
ID of the post whose tags need to be retrieved.
slug
Specify the slugs of tags to retrieve.

Example Request

http://demo.wp-api.org/wp-json/wp/v2/tags

Get tags of post 1

http://demo.wp-api.org/wp-json/wp/v2/tags?post=1

Creating a Tag

The algorithm is similar to the operation of the function wp_insert_term().

Request Type

Access: authorization required

POST /wp/v2/tags

Request Parameters

name(required)
Name of the term (tag).
description
Description of the term (tag).
slug
Slug of the term (tag), usually created from the name.
parent
ID of the parent term.
meta
Meta fields.

Example Request:

POST http://example.com/wp-json/wp/v2/tags?name=My Tag

Response

{
	"id": 6,
	"count": 0,
	"description": "",
	"link": "http://example.com/tag/my-tag/",
	"name": "My Tag",
	"slug": "my-tag",
	"taxonomy": "post_tag",
	"parent": 0,
	"meta": [],
	"_links": {
		"self": [
			{
				"href": "http://example.com/wp-json/wp/v2/tags/6"
			}
		],
		"collection": [
			{
				"href": "http://example.com/wp-json/wp/v2/tags"
			}
		],
		"about": [
			{
				"href": "http://example.com/wp-json/wp/v2/taxonomies/post_tag"
			}
		],
		"wp:post_type": [
			{
				"href": "http://example.com/wp-json/wp/v2/posts?tags=6"
			}
		],
		"curies": [
			{
				"name": "wp",
				"href": "https://api.w.org/{rel}",
				"templated": true
			}
		]
	}
}

wp/v2/tags/{id}

An OPTIONS request to the route will return a complete description of this route: endpoints, their parameters, schema.

$ curl -X OPTIONS -i http://demo.wp-api.org/wp-json/wp/v2/tags/1
GitHub
{
    "namespace": "wp/v2",
    "methods": [
        "GET",
        "POST",
        "PUT",
        "PATCH",
        "DELETE"
    ],
    "endpoints": [
        {
            "methods": [
                "GET"
            ],
            "args": {
                "id": {
                    "required": false,
                    "description": "Уникальный идентификатор элемента.",
                    "type": "integer"
                },
                "context": {
                    "required": false,
                    "default": "view",
                    "enum": [
                        "view",
                        "embed",
                        "edit"
                    ],
                    "description": "Рамки в которых сделан запрос, определяют поля в ответе.",
                    "type": "string"
                }
            }
        },
        {
            "methods": [
                "POST",
                "PUT",
                "PATCH"
            ],
            "args": {
                "id": {
                    "required": false,
                    "description": "Уникальный идентификатор элемента.",
                    "type": "integer"
                },
                "description": {
                    "required": false,
                    "description": "HTML описание элемента.",
                    "type": "string"
                },
                "name": {
                    "required": false,
                    "description": "HTML название элемента.",
                    "type": "string"
                },
                "slug": {
                    "required": false,
                    "description": "Буквенно-цифровой идентификатор элемента уникальный для его типа.",
                    "type": "string"
                },
                "meta": {
                    "required": false,
                    "description": "Мета поля.",
                    "type": "object"
                }
            }
        },
        {
            "methods": [
                "DELETE"
            ],
            "args": {
                "id": {
                    "required": false,
                    "description": "Уникальный идентификатор элемента.",
                    "type": "integer"
                },
                "force": {
                    "required": false,
                    "default": false,
                    "description": "Должно быть истинно, так как элементы не поддерживают перемещение в корзину.",
                    "type": "boolean"
                }
            }
        }
    ],
    "schema": {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "title": "tag",
        "type": "object",
        "properties": {
            "id": {
                "description": "Уникальный идентификатор элемента.",
                "type": "integer",
                "context": [
                    "view",
                    "embed",
                    "edit"
                ],
                "readonly": true
            },
            "count": {
                "description": "Число опубликованных записей элемента.",
                "type": "integer",
                "context": [
                    "view",
                    "edit"
                ],
                "readonly": true
            },
            "description": {
                "description": "HTML описание элемента.",
                "type": "string",
                "context": [
                    "view",
                    "edit"
                ]
            },
            "link": {
                "description": "URL элемента.",
                "type": "string",
                "format": "uri",
                "context": [
                    "view",
                    "embed",
                    "edit"
                ],
                "readonly": true
            },
            "name": {
                "description": "HTML название элемента.",
                "type": "string",
                "context": [
                    "view",
                    "embed",
                    "edit"
                ],
                "required": true
            },
            "slug": {
                "description": "Буквенно-цифровой идентификатор элемента уникальный для его типа.",
                "type": "string",
                "context": [
                    "view",
                    "embed",
                    "edit"
                ]
            },
            "taxonomy": {
                "description": "Тип атрибуции элемента.",
                "type": "string",
                "enum": [
                    "category",
                    "post_tag",
                    "nav_menu",
                    "link_category",
                    "post_format"
                ],
                "context": [
                    "view",
                    "embed",
                    "edit"
                ],
                "readonly": true
            },
            "meta": {
                "description": "Мета поля.",
                "type": "object",
                "context": [
                    "view",
                    "edit"
                ],
                "properties": []
            }
        }
    }
}

Getting a Tag

The algorithm is similar to the operation of the function get_tag().

Request Type

GET /wp/v2/tags/{id}

Request Parameters

id(number)
Identifier of the term.
context(string)
The area in which the request is made; defines the fields present in the response.
Can be: view, embed, edit
Default: view

Example Request

Get tag 25

http://demo.wp-api.org/wp-json/wp/v2/tags/25

Updating a Tag

The algorithm is similar to the operation of the function wp_update_term().

Request Type

Access: authorization required

POST /wp/v2/tags/{id}

Request Parameters

id(required)
ID of the term (tag).
name
Name of the term (tag).
description
Description of the term (tag).
slug
Slug of the term (tag), usually created from the name.
parent
ID of the parent term.
meta
Meta fields.

Example Request

$ curl -X POST http://demo.wp-api.org/wp-json/wp/v2/tags/25 -d '{"name":"New Name"}'

Or

POST http://example.com/wp-json/wp/v2/tags/6?name=My Tag&slug=my tag

Response

{
	"id": 6,
	"count": 0,
	"description": "",
	"link": "http://example.com/tag/my-tag/",
	"name": "My Tag",
	"slug": "my-tag",
	"taxonomy": "post_tag",
	"parent": 0,
	"meta": [],
	"_links": {
		"self": [
			{
				"href": "http://example.com/wp-json/wp/v2/tags/6"
			}
		],
		"collection": [
			{
				"href": "http://example.com/wp-json/wp/v2/tags"
			}
		],
		"about": [
			{
				"href": "http://example.com/wp-json/wp/v2/taxonomies/post_tag"
			}
		],
		"wp:post_type": [
			{
				"href": "http://example.com/wp-json/wp/v2/posts?tags=6"
			}
		],
		"curies": [
			{
				"name": "wp",
				"href": "https://api.w.org/{rel}",
				"templated": true
			}
		]
	}
}

Deleting a Tag

The algorithm is similar to the operation of the function wp_delete_term().

Request Type

Access: authorization required

DELETE /wp/v2/tags/{id}

Request Parameters

id(required)
ID of the term (tag).
force
Always must be true, as terms do not support the trash.

Example Request

$ curl -X DELETE http://example.com/wp-json/wp/v2/tags/6?force=true

Response

{
	"deleted": true,
	"previous": {
		"id": 6,
		"count": 0,
		"description": "",
		"link": "http://example.com/tag/my-tag/",
		"name": "My Tag",
		"slug": "my-tag",
		"taxonomy": "post_tag",
		"parent": 0,
		"meta": []
	}
}

Response if such a tag does not exist

{
	"code": "rest_term_invalid",
	"message": "Item does not exist.",
	"data": {
		"status": 404
	}
}