Ці маршрути дозволяють отримати/створити/оновити/видалити сторінки або окрему сторінку.
Можливі маршрути (кінцеві точки маршрутів описані нижче):
/wp/v2/pages // працює зі всіма сторінками
/wp/v2/pages/{ID} // працює із зазначеною замість {ID} сторінкою
Клас контролера: WP_REST_Posts_Controller{}
Схема ресурсу
Схема показує всі поля, які є об’єкта: поля об’єкта які поверне запит.
Параметр | Контекст | Опис |
---|
date рядок | view, edit, embed | Дата публікації сторінки у часовому поясі сайту. |
date_gmt рядок/datetime | view, edit | Дата публікації сторінки, як GMT. |
guid об’єкт | view, edit | Глобальний унікальний ідентифікатор сторінки. Лише для читання. |
id число | view, edit, embed | Унікальний ідентифікатор сторінки. Лише для читання. |
link рядок | view, edit, embed | Посилання на сторінку. Лише для читання. |
modified рядок | view, edit | Дата останньої зміни сторінки у часовому поясі сайту. Лише для читання. |
modified_gmt рядок | view, edit | Дата останньої зміни сторінки, як GMT. Лише для читання. |
slug рядок | view, edit, embed | Алфавітно-цифровий ідентифікатор сторінки унікальний для його типу. Ще називають ярликом. |
status рядок | view, edit | Статус сторінки. Може бути publish , future , draft , pending , private . |
type рядок | view, edit, embed | Тип сторінки. Лише для читання. |
password рядок | edit | Пароль для захисту доступу до контенту та цитати (уривку). |
parent число | view, edit | ID батьківської сторінки. |
title об’єкт | view, edit, embed | Заголовок сторінки. |
content об’єкт | view, edit | Контент сторінки. |
author число | view, edit, embed | Ідентифікатор (ID) автора сторінки |
excerpt об’єкт | view, edit, embed | Цитата (уривок) сторінки. |
featured_media число | view, edit, embed | Ідентифікатор (ID) мініатюри (зображення) сторінки. |
comment_status рядок | view, edit | Чи можна залишати коментарі до сторінки чи ні. Може бути open або closed . |
ping_status рядок | view, edit | Статус пінгів/трекбеків може бути open або closed . |
menu_order число | view, edit | Порядок сторінки щодо іншої сторінки. |
meta масив | view, edit | Знання метаполів. Масив об’єктів. |
template рядок | view, edit | Файл теми, який використовується для відображення сторінки. |
wp/v2/pages
Запит OPTIONS до маршруту поверне повний опис цього маршруту: ендпоінти, їх параметри, схему.
$ curl -X OPTIONS -i http://demo.wp-api.org/wp-json/wp/v2/pages
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"
},
"after": {
"required": false,
"description": "Обмежити відповідь записами опублікованими після заданої ISO8601 сумісної дати.",
"type": "string"
},
"author": {
"required": false,
"default": [],
"description": "Обмежити вибірку записами певних авторів.",
"type": "array",
"items": {
"type": "integer"
}
},
"author_exclude": {
"required": false,
"default": [],
"description": "Переконатися, що вибірка виключає записи призначені певним авторам.",
"type": "array",
"items": {
"type": "integer"
}
},
"before": {
"required": false,
"description": "Обмежити відповідь записами, опублікованими до заданої ISO8601 сумісної дати.",
"type": "string"
},
"exclude": {
"required": false,
"default": [],
"description": "Переконатися, що вибірка виключає певні ID.",
"type": "array",
"items": {
"type": "integer"
}
},
"include": {
"required": false,
"default": [],
"description": "Обмежити вибірку до певних ID.",
"type": "array",
"items": {
"type": "integer"
}
},
"menu_order": {
"required": false,
"description": "Обмежити вибірку до записів з певним значенням menu_order.",
"type": "integer"
},
"offset": {
"required": false,
"description": "Зсув вибірки на певну кількість об'єктів.",
"type": "integer"
},
"Order": {
"required": false,
"default": "desc",
"enum": [
"asc",
"desc"
],
"description": "Упорядкувати сортування атрибуту за зростанням або зменшенням.",
"type": "string"
},
"orderby": {
"required": false,
"default": "date",
"enum": [
"author",
"date",
"id",
"include",
"modified",
"parent",
"relevance",
"slug",
"include_slugs",
"title",
"menu_order"
],
"description": "Сортувати колекцію за атрибутом об'єкта.",
"type": "string"
},
"parent": {
"required": false,
"default": [],
"description": "Обмежити вибірку до певних ID батьків.",
"type": "array",
"items": {
"type": "integer"
}
},
"parent_exclude": {
"required": false,
"default": [],
"description": "Обмежити вибірку до об'єктів за винятком тих, хто має певний ID батька.",
"type": "array",
"items": {
"type": "integer"
}
},
"slug": {
"required": false,
"description": "Обмежити вибірку до записів з одним або декількома встановленими конкретними ярликами.",
"type": "array",
"items": {
"type": "string"
}
},
"status": {
"required": false,
"default": "publish",
"description": "Обмежити вибірку до записів з одним або декількома встановленими статусами.",
"type": "array",
"items": {
"enum": [
"Publish",
"Future",
"draft",
"pending",
"private",
"trash",
"auto-draft",
"inherit",
"request-pending",
"request-confirmed",
"request-failed",
"request-completed",
any
],
"type": "string"
}
}
}
},
{
"methods": [
"POST"
],
"args": {
"date": {
"required": false,
"description": "Дата публікації об'єкта за тимчасовою зоною сайту.",
"type": "string"
},
"date_gmt": {
"required": false,
"description": "Час публікації об'єкта, за GMT.",
"type": "string"
},
"slug": {
"required": false,
"description": "Буквенно-цифровий ідентифікатор для об'єкта унікальний для його типу.",
"type": "string"
},
"status": {
"required": false,
"enum": [
"Publish",
"Future",
"draft",
"pending",
"private"
],
"description": "Іменований статус для об'єкта.",
"type": "string"
},
"password": {
"required": false,
"description": "Пароль для захисту змісту та уривка.",
"type": "string"
},
"parent": {
"required": false,
"description": "ID батька об'єкта.",
"type": "integer"
},
"title": {
"required": false,
"description": "Назва для об'єкта.",
"type": "object"
},
"content": {
"required": false,
"description": "Вміст об'єкта.",
"type": "object"
},
"author": {
"required": false,
"description": "ID автора об'єкта.",
"type": "integer"
},
"excerpt": {
"required": false,
"description": "Уривок об'єкта.",
"type": "object"
},
"featured_media": {
"required": false,
"description": "ID вибраного медіа для об'єкта.",
"type": "integer"
},
"comment_status": {
"required": false,
"enum": [
"open",
"closed"
],
"description": "Чи відкриті коментарі для об'єкта.",
"type": "string"
},
"ping_status": {
"required": false,
"enum": [
"open",
"closed"
],
"description": "Чи приймає об'єкт сповіщення.",
"type": "string"
},
"menu_order": {
"required": false,
"description": "Порядок об'єкта по відношенню до інших об'єктів того ж типу.",
"type": "integer"
},
"meta": {
"required": false,
"description": "Мета поля.",
"type": "object"
},
"template": {
"required": false,
"description": "Файл теми, який використовується для показу об'єкта.",
"type": "string"
}
}
}
],
"Schema": {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "page",
"type": "object",
"properties": {
"date": {
"description": "Дата публікації об'єкта за тимчасовою зоною сайту.",
"type": "string",
"format": "date-time",
"context": [
"view",
"edit",
"embed"
]
},
"date_gmt": {
"description": "Час публікації об'єкта, за GMT.",
"type": "string",
"format": "date-time",
"context": [
"view",
"edit"
]
},
"guid": {
"description": "Глобальний унікальний ідентифікатор об'єкта.",
"type": "object",
"context": [
"view",
"edit"
],
"readonly": true,
"properties": {
"raw": {
"description": "GUID для об'єкта, як він існує в базі даних.",
"type": "string",
"context": [
"edit"
],
"readonly": true
},
"rendered": {
"description": "GUID для об'єкта, перетворений для показу.",
"type": "string",
"context": [
"view",
"edit"
],
"readonly": true
}
}
},
"id": {
"description": "Унікальний ідентифікатор об'єкта.",
"type": "integer",
"context": [
"view",
"edit",
"embed"
],
"readonly": true
},
"link": {
"description": "URL об'єкта.",
"type": "string",
"format": "uri",
"context": [
"view",
"edit",
"embed"
],
"readonly": true
},
"modified": {
"description": "Дата останньої зміни об'єкта за тимчасовою зоною сайту.",
"type": "string",
"format": "date-time",
"context": [
"view",
"edit"
],
"readonly": true
},
"modified_gmt": {
"description": "Дата останньої зміни об'єкта в GMT.",
"type": "string",
"format": "date-time",
"context": [
"view",
"edit"
],
"readonly": true
},
"slug": {
"description": "Буквенно-цифровий ідентифікатор для об'єкта унікальний для його типу.",
"type": "string",
"context": [
"view",
"edit",
"embed"
]
},
"status": {
"description": "Іменований статус для об'єкта.",
"type": "string",
"enum": [
"Publish",
"Future",
"draft",
"pending",
"private"
],
"context": [
"view",
"edit"
]
},
"type": {
"description": "Тип запису для об'єкта.",
"type": "string",
"context": [
"view",
"edit",
"embed"
],
"readonly": true
},
"password": {
"description": "Пароль для захисту змісту та уривка.",
"type": "string",
"context": [
"edit"
]
},
"parent": {
"description": "ID батька об'єкта.",
"type": "integer",
"context": [
"view",
"edit"
]
},
"title": {
"description": "Назва для об'єкта.",
"type": "object",
"context": [
"view",
"edit",
"embed"
],
"properties": {
"raw": {
"description": "Назва об'єкта як вона існує в базі даних.",
"type": "string",
"context": [
"edit"
]
},
"rendered": {
"description": "HTML назва об'єкта, перетворена для показу.",
"type": "string",
"context": [
"view",
"edit",
"embed"
],
"readonly": true
}
}
},
"content": {
"description": "Вміст об'єкта.",
"type": "object",
"context": [
"view",
"edit"
],
"properties": {
"raw": {
"description": "Вміст об'єкта, як він існує в базі даних.",
"type": "string",
"context": [
"edit"
]
},
"rendered": {
"description": "HTML вміст об'єкта перетворений для показу.",
"type": "string",
"context": [
"view",
"edit"
],
"readonly": true
},
"protected": {
"description": "Чи захищено вміст паролем.",
"type": "boolean",
"context": [
"view",
"edit",
"embed"
],
"readonly": true
}
}
},
"author": {
"description": "ID автора об'єкта.",
"type": "integer",
"context": [
"view",
"edit",
"embed"
]
},
"excerpt": {
"description": "Уривок об'єкта.",
"type": "object",
"context": [
"view",
"edit",
"embed"
],
"properties": {
"raw": {
"description": "Уривок об'єкта як він існує в базі даних.",
"type": "string",
"context": [
"edit"
]
},
"rendered": {
"description": "HTML уривок об'єкта, перетворений для показу.",
"type": "string",
"context": [
"view",
"edit",
"embed"
],
"readonly": true
},
"protected": {
"description": "Чи захищати паролем уривок.",
"type": "boolean",
"context": [
"view",
"edit",
"embed"
],
"readonly": true
}
}
},
"featured_media": {
"description": "ID вибраного медіа для об'єкта.",
"type": "integer",
"context": [
"view",
"edit",
"embed"
]
},
"comment_status": {
"description": "Чи відкриті коментарі для об'єкта.",
"type": "string",
"enum": [
"open",
"closed"
],
"context": [
"view",
"edit"
]
},
"ping_status": {
"description": "Чи приймає об'єкт сповіщення.",
"type": "string",
"enum": [
"open",
"closed"
],
"context": [
"view",
"edit"
]
},
"menu_order": {
"description": "Порядок об'єкта по відношенню до інших об'єктів того ж типу.",
"type": "integer",
"context": [
"view",
"edit"
]
},
"meta": {
"description": "Мета поля.",
"type": "object",
"context": [
"view",
"edit"
],
"properties": []
},
"template": {
"description": "Файл теми, який використовується для показу об'єкта.",
"type": "string",
"context": [
"view",
"edit"
]
}
},
"links": [
{
"rel": "https://api.w.org/action-publish",
"title": "Поточний користувач може опублікувати цей запис.",
"href": "http://wptest.ru/wp-json/wp/v2/pages/{id}",
"targetSchema": {
"type": "object",
"properties": {
"status": {
"type": "string",
"enum": [
"Publish",
"future"
]
}
}
}
},
{
"rel": "https://api.w.org/action-assign-author",
"title": "Поточний користувач може змінити автора для цього запису.",
"href": "http://wptest.ru/wp-json/wp/v2/pages/{id}",
"targetSchema": {
"type": "object",
"properties": {
"author": {
"type": "integer"
}
}
}
}
]
},
"_links": {
"self": "http://wptest.ru/wp-json/wp/v2/pages"
}
}
Список сторінок
За один запит можна отримати колекцію зі сторінок з тих чи інших умов. Алгоритм схожий з роботою класу WP_Query та функцій на його основі.
Вид запиту
Доступ: публічний
GET /wp/v2/pages
Параметри запиту
- context
- Область, у якій виконується запит; визначає поля, присутні у відповіді. Можливо
view ,
embed ,
edit .Типово: view
- page
- Поточна сторінка колекції.
За замовчуванням: 1
- per_page
- Максимальна кількість сторінок у результуючому наборі.
Типово: 10
- search
- Обмеження за кількістю сторінок, що повертаються при пошуку.
- after
- Обмежити відповідь на сторінки, опубліковані після заданої дати, що відповідає ISO8601.
- before
- Обмежити відповідь на сторінки, опубліковані до заданої дати, що відповідає ISO8601.
- author
- Вказує сторінки яких авторів треба повернути.
- author_exclude
- Вказує сторінки яких авторів не треба повертати.
- exclude
- Виключає з набору сторінки за їх ID.
- include
- Включає набір сторінки за їх ID. У наборі будуть лише ті сторінки, ID яких були вказані.
- menu_order
- Включає в комплект сторінки з певним значенням параметра
menu_order . - offset
- Усунення (відступ) набору результатів на вказане число.
За замовчуванням: 1
- order
- Сортування сторінок у вибірці. Може бути
asc або
desc .За замовчуванням: desc
- orderby
- Сортування сторінок у вибірці за атрибутами. Можливо
author ,
date ,
id ,
include ,
modified ,
parent ,
relevance ,
slug ,
title .Типово: date
- slug
- Обмеження вибірки за вказаним одним ярликом сторінки або кількома.
- status
- Обмеження вибірки за одним статусом чи декільком.
Типово: publish
- parent
- Обмеження вибірки за певним батьківським ID.
- parent_exclude
- Виключає з набору сторінки за ID батьківських сторінок.
Приклад запиту
Посилання робітники можна відкрити в браузері і подивитися результат.
1) Запит на отримання масиву всіх сторінок:
https://demo.wp-api.org/wp-json/wp/v2/pages/
Повернеться масив об’єктів, де кожен об’єкт сторінки схожий на те, що описаний у пункті “Отримати сторінку”:
[
{
... дані сторінки <id> ...
},
{
... дані сторінки <id> ...
},
{
... дані сторінки <id> ...
}
]
2) Отримаємо сторінки автора 1
https://demo.wp-api.org/wp-json/wp/v2/pages/?author=1
Створення сторінки
Алгоритм схожий на роботу функції wp_insert_post() .
Вид запиту
Доступ: потрібна авторизація
POST /wp/v2/pages
Параметри запиту
- date
(рядок) - Дата публікації сторінки у часовому поясі сайту.
- date_gmt
(рядок/datetime) - Дата публікації сторінки, як GMT.
- slug
(рядок) - Алфавітно-цифровий ідентифікатор сторінки унікальний для його типу. Ще називають ярликом.
- status
(рядок) - Статус сторінки. Може бути
publish ,
future ,
draft ,
pending ,
private . - password
(рядок) - Пароль для захисту доступу до контенту та цитати (уривку).
- parent
(число) - ID батьківської сторінки.
- title
(об’єкт) - Заголовок сторінки.
- content
(об’єкт) - Контент сторінки.
- author
(число) - Ідентифікатор автора сторінки.
- excerpt
(об’єкт) - Цитата (уривок) сторінки.
- featured_media
(число) - Ідентифікатор (ID) мініатюри (зображення) сторінки.
- comment_status
(рядок) - Чи можна залишати коментарі до сторінки чи ні. Може бути
open або
closed . - ping_status
(рядок) - Статус пінгів/трекбеків може бути
open або
closed . - menu_order
- Порядок сторінки щодо іншої сторінки.
- meta
(масив) - Знання метаполів. Масив об’єктів.
- template
(рядок) - Файл теми, який використовується для відображення сторінки.
Приклад запиту
POST http://example.com/wp-json/wp/v2/pages/?title=Заголовок&slug=my-post&status=publish
wp/v2/pages/{id}
Запит OPTIONS до маршруту поверне повний опис цього маршруту: ендпоінти, їх параметри, схему.
$ curl -X OPTIONS -i http://demo.wp-api.org/wp-json/wp/v2/pages/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"
},
"password": {
"required": false,
"description": "Пароль для запису, якщо він захищений паролем.",
"type": "string"
}
}
},
{
"methods": [
"POST",
"PUT",
"PATCH"
],
"args": {
"id": {
"required": false,
"description": "Унікальний ідентифікатор об'єкта.",
"type": "integer"
},
"date": {
"required": false,
"description": "Дата публікації об'єкта за тимчасовою зоною сайту.",
"type": "string"
},
"date_gmt": {
"required": false,
"description": "Час публікації об'єкта, за GMT.",
"type": "string"
},
"slug": {
"required": false,
"description": "Буквенно-цифровий ідентифікатор для об'єкта унікальний для його типу.",
"type": "string"
},
"status": {
"required": false,
"enum": [
"Publish",
"Future",
"draft",
"pending",
"private"
],
"description": "Іменований статус для об'єкта.",
"type": "string"
},
"password": {
"required": false,
"description": "Пароль для захисту змісту та уривка.",
"type": "string"
},
"parent": {
"required": false,
"description": "ID батька об'єкта.",
"type": "integer"
},
"title": {
"required": false,
"description": "Назва для об'єкта.",
"type": "object"
},
"content": {
"required": false,
"description": "Вміст об'єкта.",
"type": "object"
},
"author": {
"required": false,
"description": "ID автора об'єкта.",
"type": "integer"
},
"excerpt": {
"required": false,
"description": "Уривок об'єкта.",
"type": "object"
},
"featured_media": {
"required": false,
"description": "ID вибраного медіа для об'єкта.",
"type": "integer"
},
"comment_status": {
"required": false,
"enum": [
"open",
"closed"
],
"description": "Чи відкриті коментарі для об'єкта.",
"type": "string"
},
"ping_status": {
"required": false,
"enum": [
"open",
"closed"
],
"description": "Чи приймає об'єкт сповіщення.",
"type": "string"
},
"menu_order": {
"required": false,
"description": "Порядок об'єкта по відношенню до інших об'єктів того ж типу.",
"type": "integer"
},
"meta": {
"required": false,
"description": "Мета поля.",
"type": "object"
},
"template": {
"required": false,
"description": "Файл теми, який використовується для показу об'єкта.",
"type": "string"
}
}
},
{
"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": "page",
"type": "object",
"properties": {
"date": {
"description": "Дата публікації об'єкта за тимчасовою зоною сайту.",
"type": "string",
"format": "date-time",
"context": [
"view",
"edit",
"embed"
]
},
"date_gmt": {
"description": "Час публікації об'єкта, за GMT.",
"type": "string",
"format": "date-time",
"context": [
"view",
"edit"
]
},
"guid": {
"description": "Глобальний унікальний ідентифікатор об'єкта.",
"type": "object",
"context": [
"view",
"edit"
],
"readonly": true,
"properties": {
"raw": {
"description": "GUID для об'єкта, як він існує в базі даних.",
"type": "string",
"context": [
"edit"
],
"readonly": true
},
"rendered": {
"description": "GUID для об'єкта, перетворений для показу.",
"type": "string",
"context": [
"view",
"edit"
],
"readonly": true
}
}
},
"id": {
"description": "Унікальний ідентифікатор об'єкта.",
"type": "integer",
"context": [
"view",
"edit",
"embed"
],
"readonly": true
},
"link": {
"description": "URL об'єкта.",
"type": "string",
"format": "uri",
"context": [
"view",
"edit",
"embed"
],
"readonly": true
},
"modified": {
"description": "Дата останньої зміни об'єкта за тимчасовою зоною сайту.",
"type": "string",
"format": "date-time",
"context": [
"view",
"edit"
],
"readonly": true
},
"modified_gmt": {
"description": "Дата останньої зміни об'єкта в GMT.",
"type": "string",
"format": "date-time",
"context": [
"view",
"edit"
],
"readonly": true
},
"slug": {
"description": "Буквенно-цифровий ідентифікатор для об'єкта унікальний для його типу.",
"type": "string",
"context": [
"view",
"edit",
"embed"
]
},
"status": {
"description": "Іменований статус для об'єкта.",
"type": "string",
"enum": [
"Publish",
"Future",
"draft",
"pending",
"private"
],
"context": [
"view",
"edit"
]
},
"type": {
"description": "Тип запису для об'єкта.",
"type": "string",
"context": [
"view",
"edit",
"embed"
],
"readonly": true
},
"password": {
"description": "Пароль для захисту змісту та уривка.",
"type": "string",
"context": [
"edit"
]
},
"parent": {
"description": "ID батька об'єкта.",
"type": "integer",
"context": [
"view",
"edit"
]
},
"title": {
"description": "Назва для об'єкта.",
"type": "object",
"context": [
"view",
"edit",
"embed"
],
"properties": {
"raw": {
"description": "Назва об'єкта як вона існує в базі даних.",
"type": "string",
"context": [
"edit"
]
},
"rendered": {
"description": "HTML назва об'єкта, перетворена для показу.",
"type": "string",
"context": [
"view",
"edit",
"embed"
],
"readonly": true
}
}
},
"content": {
"description": "Вміст об'єкта.",
"type": "object",
"context": [
"view",
"edit"
],
"properties": {
"raw": {
"description": "Вміст об'єкта, як він існує в базі даних.",
"type": "string",
"context": [
"edit"
]
},
"rendered": {
"description": "HTML вміст об'єкта перетворений для показу.",
"type": "string",
"context": [
"view",
"edit"
],
"readonly": true
},
"protected": {
"description": "Чи захищено вміст паролем.",
"type": "boolean",
"context": [
"view",
"edit",
"embed"
],
"readonly": true
}
}
},
"author": {
"description": "ID автора об'єкта.",
"type": "integer",
"context": [
"view",
"edit",
"embed"
]
},
"excerpt": {
"description": "Уривок об'єкта.",
"type": "object",
"context": [
"view",
"edit",
"embed"
],
"properties": {
"raw": {
"description": "Уривок об'єкта як він існує в базі даних.",
"type": "string",
"context": [
"edit"
]
},
"rendered": {
"description": "HTML уривок об'єкта, перетворений для показу.",
"type": "string",
"context": [
"view",
"edit",
"embed"
],
"readonly": true
},
"protected": {
"description": "Чи захищати паролем уривок.",
"type": "boolean",
"context": [
"view",
"edit",
"embed"
],
"readonly": true
}
}
},
"featured_media": {
"description": "ID вибраного медіа для об'єкта.",
"type": "integer",
"context": [
"view",
"edit",
"embed"
]
},
"comment_status": {
"description": "Чи відкриті коментарі для об'єкта.",
"type": "string",
"enum": [
"open",
"closed"
],
"context": [
"view",
"edit"
]
},
"ping_status": {
"description": "Чи приймає об'єкт сповіщення.",
"type": "string",
"enum": [
"open",
"closed"
],
"context": [
"view",
"edit"
]
},
"menu_order": {
"description": "Порядок об'єкта по відношенню до інших об'єктів того ж типу.",
"type": "integer",
"context": [
"view",
"edit"
]
},
"meta": {
"description": "Мета поля.",
"type": "object",
"context": [
"view",
"edit"
],
"properties": []
},
"template": {
"description": "Файл теми, який використовується для показу об'єкта.",
"type": "string",
"context": [
"view",
"edit"
]
}
},
"links": [
{
"rel": "https://api.w.org/action-publish",
"title": "Поточний користувач може опублікувати цей запис.",
"href": "http://wptest.ru/wp-json/wp/v2/pages/{id}",
"targetSchema": {
"type": "object",
"properties": {
"status": {
"type": "string",
"enum": [
"Publish",
"future"
]
}
}
}
},
{
"rel": "https://api.w.org/action-assign-author",
"title": "Поточний користувач може змінити автора для цього запису.",
"href": "http://wptest.ru/wp-json/wp/v2/pages/{id}",
"targetSchema": {
"type": "object",
"properties": {
"author": {
"type": "integer"
}
}
}
}
]
}
}
Отримання сторінки
Алгоритм схожий на роботу функції get_post() .
Вид запиту
Доступ: публічний
GET /wp/v2/pages/{id}
Параметри запиту
- id
(обов’язковий) - Унікальний ідентифікатор сторінки
- context
- Область, у якій виконується запит; визначає поля, присутні у відповіді. Можливо
view ,
embed ,
edit .Типово: view
- password
- Пароль для отримання доступу до захищеної паролем сторінки.
Приклад запиту
$ curl http://demo.wp-api.org/wp-json/wp/v2/pages/<id>
Приклад запиту на об’єкт сторінки з ID=850:
https://demo.wp-api.org/wp-json/wp/v2/pages/850
Відповідь:
{
"id": 850,
"date": "2018-08-25T13:00:35",
"date_gmt": "2018-08-25T10:00:35",
"guid": {
"rendered": "http://wp-test.ru/?page_id=850"
},
"modified": "2018-08-29T10:55:34",
"modified_gmt": "2018-08-29T07:55:34",
"slug": "contacts",
"status": "publish",
"type": "page",
"link": "http://wp-test.ru/contacts/",
"title": {
"rendered": "Контакти"
},
"content": {
"rendered": "Звернутися до нас можна через цю форму</p> HTML Код форми",
"protected": false
},
"excerpt": {
"rendered": "<p>Зв'язатися з нами можна через цю форму</p>n",
"protected": false
},
"author": 1,
"featured_media": 0,
"parent": 0,
"menu_order": 0,
"comment_status": "closed",
"ping_status": "closed",
"template": "",
"meta": [],
"_links": {
"self": [
{
"href": "http://wp-test.ru/wp-json/wp/v2/pages/850"
}
],
"collection": [
{
"href": "http://wp-test.ru/wp-json/wp/v2/pages"
}
],
"about": [
{
"href": "http://wp-test.ru/wp-json/wp/v2/types/page"
}
],
"author": [
{
"embeddable": true,
"href": "http://wp-test.ru/wp-json/wp/v2/users/1"
}
],
"replies": [
{
"embeddable": true,
"href": "http://wp-test.ru/wp-json/wp/v2/comments?post=850"
}
],
"version-history": [
{
"count": 3,
"href": "http://wp-test.ru/wp-json/wp/v2/pages/850/revisions"
}
],
"predecessor-version": [
{
"id": 861,
"href": "http://wp-test.ru/wp-json/wp/v2/pages/850/revisions/861"
}
],
"wp:attachment": [
{
"href": "http://wp-test.ru/wp-json/wp/v2/media?parent=850"
}
],
"curies": [
{
"name": "wp",
"href": "https://api.w.org/{rel}",
"templated": true
}
]
}
}
Оновлення сторінки
Алгоритм схожий на роботу функції wp_update_post() .
Вид запиту
Доступ: потрібна авторизація
POST|PUT|PATCH /wp/v2/pages/{id}
Параметри запиту
- id
(обов’язковий) - Унікальний ідентифікатор сторінки, яку потрібно оновити.
- Інші параметри
- Повністю збігаються з параметрами
“Створення сторінки” .
Приклад запиту
$ curl -X POST http://demo.wp-api.org/wp-json/wp/v2/pages/<id> -d '{"title":"My New Title"}'
Видалення сторінки
Алгоритм схожий на роботу функції wp_delete_post() .
Вид запиту
Доступ: потрібна авторизація
DELETE /wp/v2/pages/{id}
Параметри запиту
- id
(обов’язковий) - Унікальний ідентифікатор сторінки, яку потрібно видалити.
- force
(логічний) - Видаляти повз кошик, якщо він увімкнений.
true
– Примусове видалення назавжди.Типово: false
Приклад запиту
Видалимо сторінку 125:
$ curl -X DELETE http://demo.wp-api.org/wp-json/wp/v2/pages/125