Пошук (search)
Цей маршрут дають змогу шукати по всьому вмісту WordPress. Додано до WP 5.0.
Можливі маршрути (кінцеві точки маршрутів описані нижче):
/wp/v2/search
Клас контролера: WP_REST_Search_Controller{}
Схема маршруту
Зміст:
Схема ресурсу
Опис маршруту
Запит OPTIONS до маршруту поверне повний опис цього маршруту: ендпоінти, їх параметри, схему.
$ curl -X OPTIONS -i http://demo.wp-api.org/wp-json/wp/v2/search
Пошук по сайту
Вид запиту
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": "Коррентна сторінка колекції.",
"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": "Звичайні результати для того, щоб matching a string.",
"type": "string"
},
"type": {
"required": false,
"default": "post",
"enum": [
"post"
],
"description": "Звичайні результати до елементів object type.",
"type": "string"
},
"subtype": {
"required": false,
"default": "any",
"description": "Звичайні результати до елементів одного або більше об'єктів 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"
}
]
}
},
...
...
...
]