Поиск (search)
Этот маршрут позволяют искать по всему содержимому WordPress. Добавлено в WP 5.0.
Возможные маршруты (конечные точки маршрутов описаны ниже):
/wp/v2/search
Класс контроллера: WP_REST_Search_Controller{}
Оглавление:
Схема ресурса
Схема показывает все поля, которые существуют для объекта: поля объекта которые вернет запрос.
| Параметр | Контекст | Описание |
|---|---|---|
| id integer/string readonly |
view, embed | Уникальный идентификатор для объекта. |
| title string readonly |
view, embed | Название для объекта. |
| url string readonly |
view, embed | URL объекта. |
| type string readonly |
view, embed | Тип объекта. |
| subtype string readonly |
view, embed | Подтип объекта. |
Описание маршрута
Запрос OPTIONS к маршруту вернет полное описание этого маршрута: эндпоинты их параметры, схему.
$ curl -X OPTIONS -i http://demo.wp-api.org/wp-json/wp/v2/searchGitHub
Поиск по сайту
Вид запроса
GET /wp-json/wp/v2/search
Параметры запроса
"context": {
"required": false,
"default": "view",
"enum": [
"view",
"embed"
],
"description": "Scope under which the request is made; determines fields present in response.",
"type": "string"
},
"page": {
"required": false,
"default": 1,
"description": "Current page of the collection.",
"type": "integer"
},
"per_page": {
"required": false,
"default": 10,
"description": "Maximum number of items to be returned in result set.",
"type": "integer"
},
"search": {
"required": false,
"description": "Limit results to those matching a string.",
"type": "string"
},
"type": {
"required": false,
"default": "post",
"enum": [
"post"
],
"description": "Limit results to items of an object type.",
"type": "string"
},
"subtype": {
"required": false,
"default": "any",
"description": "Limit results to items of one or more object subtypes.",
"type": "array",
"items": {
"enum": [
"post",
"page",
"any"
],
"type": "string"
}
}
Пример запроса
$ curl http://example.com/wp-json/wp/v2/search
Ответ:
[
{
"id": 1,
"title": "Hello world!",
"url": "https://demo.wp-api.org/2017/05/23/hello-world/",
"type": "post",
"subtype": "post",
"_links": {
"self": [
{
"embeddable": true,
"href": "https://demo.wp-api.org/wp-json/wp/v2/posts/1"
}
],
"about": [
{
"href": "https://demo.wp-api.org/wp-json/wp/v2/types/post"
}
],
"collection": [
{
"href": "https://demo.wp-api.org/wp-json/wp/v2/search"
}
]
}
},
{
"id": 2,
"title": "Sample Page",
"url": "https://demo.wp-api.org/sample-page/",
"type": "post",
"subtype": "page",
"_links": {
"self": [
{
"embeddable": true,
"href": "https://demo.wp-api.org/wp-json/wp/v2/pages/2"
}
],
"about": [
{
"href": "https://demo.wp-api.org/wp-json/wp/v2/types/page"
}
],
"collection": [
{
"href": "https://demo.wp-api.org/wp-json/wp/v2/search"
}
]
}
},
...
...
...
]