Ці маршрути дозволяють отримати/створити/оновити/видалити записи або окремий запис (пост).
Можливі маршрути (кінцеві точки маршрутів описані нижче):
/wp/v2/posts // працює з усіма постами
/wp/v2/posts/{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 | Пароль для захисту доступу до контенту та цитати (уривку). |
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 . |
format рядок | view, edit | Формат запису. Можливо: standard , aside , chat , gallery , link , image , quote , status , video , audio . |
meta масив | view, edit | Значення метаполів. Масив об’єктів. |
sticky true/false | view, edit | Чи є запис липким чи ні. |
template рядок | view, edit | Файл теми, який використовується для відображення запису. |
categories масив | view, edit | Масив із ID рубрик, до яких належить запис. |
tags масив | view, edit | Масив із ID міток (тегів), до яких належить запис. |
wp/v2/posts
Запит OPTIONS до маршруту поверне повний опис цього маршруту: ендпоінти, їх параметри, схему.
$ curl -X OPTIONS -i http://demo.wp-api.org/wp-json/wp/v2/posts
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"
},
"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"
},
"format": {
"required": false,
"enum": [
"standard",
"aside",
"chat",
"gallery",
"link",
"image",
"quote",
"status",
"video",
"audio"
],
"description": "Формат для об'єкта.",
"type": "string"
},
"meta": {
"required": false,
"description": "Мета поля.",
"type": "object"
},
"sticky": {
"required": false,
"description": "Вважати об'єкт приліпленим чи ні.",
"type": "boolean"
},
"template": {
"required": false,
"description": "Файл теми, який використовується для показу об'єкта.",
"type": "string"
},
"categories": {
"required": false,
"description": "Елементи призначені об'єкту в таксономії категорії.",
"type": "array",
"items": {
"type": "integer"
}
},
"tags": {
"required": false,
"description": "Елементи призначені об'єкту в таксономії post_tag.",
"type": "array",
"items": {
"type": "integer"
}
}
}
},
{
"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": "post",
"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"
]
},
"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"
]
},
"format": {
"description": "Формат для об'єкта.",
"type": "string",
"enum": [
"standard",
"aside",
"chat",
"gallery",
"link",
"image",
"quote",
"status",
"video",
"audio"
],
"context": [
"view",
"edit"
]
},
"meta": {
"description": "Мета поля.",
"type": "object",
"context": [
"view",
"edit"
],
"properties": []
},
"sticky": {
"description": "Вважати об'єкт приліпленим чи ні.",
"type": "boolean",
"context": [
"view",
"edit"
]
},
"template": {
"description": "Файл теми, який використовується для показу об'єкта.",
"type": "string",
"context": [
"view",
"edit"
]
},
"categories": {
"description": "Елементи призначені об'єкту в таксономії категорії.",
"type": "array",
"items": {
"type": "integer"
},
"context": [
"view",
"edit"
]
},
"tags": {
"description": "Елементи призначені об'єкту в таксономії post_tag.",
"type": "array",
"items": {
"type": "integer"
},
"context": [
"view",
"edit"
]
}
},
"links": [
{
"rel": "https://api.w.org/action-publish",
"title": "Поточний користувач може опублікувати цей запис.",
"href": "http://wptest.ru/wp-json/wp/v2/posts/{id}",
"targetSchema": {
"type": "object",
"properties": {
"status": {
"type": "string",
"enum": [
"Publish",
"future"
]
}
}
}
},
{
"rel": "https://api.w.org/action-sticky",
"title": "Поточний користувач може зробити цей запис прикріпленим.",
"href": "http://wptest.ru/wp-json/wp/v2/posts/{id}",
"targetSchema": {
"type": "object",
"properties": {
"sticky": {
"type": "boolean"
}
}
}
},
{
"rel": "https://api.w.org/action-assign-author",
"title": "Поточний користувач може змінити автора для цього запису.",
"href": "http://wptest.ru/wp-json/wp/v2/posts/{id}",
"targetSchema": {
"type": "object",
"properties": {
"author": {
"type": "integer"
}
}
}
},
{
"rel": "https://api.w.org/action-assign-categories",
"title": "Поточний користувач може призначати елементи в таксономії категорії.",
"href": "http://wptest.ru/wp-json/wp/v2/posts/{id}",
"targetSchema": {
"type": "object",
"properties": {
"categories": {
"type": "array",
"items": {
"type": "integer"
}
}
}
}
},
{
"rel": "https://api.w.org/action-create-categories",
"title": "Поточний користувач може створювати елементи в таксономії категорії.",
"href": "http://wptest.ru/wp-json/wp/v2/posts/{id}",
"targetSchema": {
"type": "object",
"properties": {
"categories": {
"type": "array",
"items": {
"type": "integer"
}
}
}
}
},
{
"rel": "https://api.w.org/action-assign-tags",
"title": "Поточний користувач може призначати елементи в таксономії post_tag.",
"href": "http://wptest.ru/wp-json/wp/v2/posts/{id}",
"targetSchema": {
"type": "object",
"properties": {
"tags": {
"type": "array",
"items": {
"type": "integer"
}
}
}
}
},
{
"rel": "https://api.w.org/action-create-tags",
"title": "Поточний користувач може створювати елементи в таксономії post_tag.",
"href": "http://wptest.ru/wp-json/wp/v2/posts/{id}",
"targetSchema": {
"type": "object",
"properties": {
"tags": {
"type": "array",
"items": {
"type": "integer"
}
}
}
}
}
]
}
}
Список записів
За один запит можна отримати колекцію із записів з тих чи інших умов. Алгоритм схожий з роботою класу WP_Query та функцій на його основі.
Вид запиту
Доступ: публічний
GET /wp/v2/posts
Параметри запиту
- context
- Область, у якій виконується запит; визначає поля, присутні у відповіді. Можливо
view ,
embed ,
edit .Типово: view
- page
- Сторінка колекції (пагінації).
За замовчуванням: 1
- per_page
- Максимальна кількість записів у результуючому наборі.
За замовчуванням: 10 (від 1 до 100 включно)
- search
- Обмежити відповідь за записами рядком (пошуковою фразою).
- after
- Обмежити відповідь на записи, опубліковані після заданої дати, що відповідає ISO8601.
- before
- Обмежити відповідь на записи, опубліковані до заданої дати, що відповідає ISO8601.
- author
- Вказує записи яких авторів треба повернути.
- author_exclude
- Зазначає записи яких авторів не треба повертати.
- exclude
- Виключає з набору запису з їхнього ID.
- include
- Включає запис записів за їх ID. У наборі будуть лише ті записи, ID яких були вказані.
- offset
- Усунення (відступ) набору результатів на вказане число.
За замовчуванням: 1
- order
- Сортування записів у вибірці. Може бути
asc або
desc .За замовчуванням: desc
- orderby
- Сортування записів у вибірці за атрибутами. Можливо
author ,
date ,
id ,
include ,
modified ,
parent ,
relevance ,
slug ,
title .Типово: date
- slug
- Обмеження вибірки за вказаним одним ярликом запису або декільком.
- status
- Обмеження вибірки за одним статусом чи декільком.
Типово: publish
- categories
- Обмеження вибірки за вказаною категорією (рубрикою) або рубриками.
- categories_exclude:
- Виключає із вибірки записи, що належать зазначеній категорії (рубриці) або рубрикам.
- tags
- Обмеження вибірки за вказаною міткою (тегом) або мітками.
- tags_exclude:
- Виключає із вибірки записи, що належать зазначеній мітці (тегу) або міткам.
- sticky
- Вибірка складатиметься лише з “липких” записів.
Приклад запиту
Посилання робітники можна відкрити в браузері і подивитися результат.
1) Запит отримання масиву всіх записів:
https://demo.wp-api.org/wp-json/wp/v2/posts/
Повернеться масив об’єктів, де кожен об’єкт запису схожий на те, що описаний у пункті “Отримати запис”:
[
{
... дані запису <id> ...
},
{
... дані запису <id> ...
},
{
... дані запису <id> ...
}
]
2) Поверне записи, які мають автор з ID=1
https://demo.wp-api.org/wp-json/wp/v2/posts/?author=1
3) Поверне записи, які мають автор з ID=1 і які належать рубриці з ID=11
https://demo.wp-api.org/wp-json/wp/v2/posts/?author=1&categories=11
Створення запису
Алгоритм схожий на роботу функції wp_insert_post() .
Вид запиту
Доступ: потрібна авторизація
POST /wp/v2/posts
Параметри запиту
- date
(рядок) - Дата публікації запису у часовому поясі сайту.
- date_gmt
(рядок/datetime) - Дата публікації запису, як GMT.
- slug
(рядок) - Алфавітно-цифровий ідентифікатор запису унікальний для його типу. Ще називають ярликом.
- status
(рядок) - Статус запису. Може бути
publish ,
future ,
draft ,
pending ,
private . - password
(рядок) - Пароль для захисту доступу до контенту та цитати (уривку).
- title
(об’єкт) - Заголовок запису.
- content
(об’єкт) - Контент запису.
- author
(число) - Ідентифікатор автора запису.
- excerpt
(об’єкт) - Цитата (уривок) запису.
- featured_media
(число) - Ідентифікатор (ID) мініатюри (зображення) запису.
- comment_status
(рядок) - Чи можна залишати коментарі до запису чи ні. Може бути
open або
closed . - ping_status
(рядок) - Статус пінгів/трекбеків може бути
open або
closed . - format
(рядок) - Статус запису. Можливо:
standard ,
aside ,
chat ,
gallery ,
link ,
image ,
quote ,
status ,
video ,
audio . - meta
(масив) - Значення метаполів. Масив об’єктів.
- sticky
(логічний) - Чи є запис липким чи ні.
- template
(рядок) - Файл теми, який використовується для відображення запису.
- categories
(масив) - Масив із ID рубрик (категорій), до яких належить запис.
- tags
(масив) - Масив із ID міток (тегів), до яких належить запис.
Приклад запиту
POST http://example.com/wp-json/wp/v2/posts/?title=Заголовок&slug=my-post&status=publish
wp/v2/posts/{id}
Запит OPTIONS до маршруту поверне повний опис цього маршруту: ендпоінти, їх параметри, схему.
$ curl -X OPTIONS -i http://demo.wp-api.org/wp-json/wp/v2/posts/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"
},
"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"
},
"format": {
"required": false,
"enum": [
"standard",
"aside",
"chat",
"gallery",
"link",
"image",
"quote",
"status",
"video",
"audio"
],
"description": "Формат для об'єкта.",
"type": "string"
},
"meta": {
"required": false,
"description": "Мета поля.",
"type": "object"
},
"sticky": {
"required": false,
"description": "Вважати об'єкт приліпленим чи ні.",
"type": "boolean"
},
"template": {
"required": false,
"description": "Файл теми, який використовується для показу об'єкта.",
"type": "string"
},
"categories": {
"required": false,
"description": "Елементи призначені об'єкту в таксономії категорії.",
"type": "array",
"items": {
"type": "integer"
}
},
"tags": {
"required": false,
"description": "Елементи призначені об'єкту в таксономії post_tag.",
"type": "array",
"items": {
"type": "integer"
}
}
}
},
{
"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": "post",
"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"
]
},
"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"
]
},
"format": {
"description": "Формат для об'єкта.",
"type": "string",
"enum": [
"standard",
"aside",
"chat",
"gallery",
"link",
"image",
"quote",
"status",
"video",
"audio"
],
"context": [
"view",
"edit"
]
},
"meta": {
"description": "Мета поля.",
"type": "object",
"context": [
"view",
"edit"
],
"properties": []
},
"sticky": {
"description": "Вважати об'єкт приліпленим чи ні.",
"type": "boolean",
"context": [
"view",
"edit"
]
},
"template": {
"description": "Файл теми, який використовується для показу об'єкта.",
"type": "string",
"context": [
"view",
"edit"
]
},
"categories": {
"description": "Елементи призначені об'єкту в таксономії категорії.",
"type": "array",
"items": {
"type": "integer"
},
"context": [
"view",
"edit"
]
},
"tags": {
"description": "Елементи призначені об'єкту в таксономії post_tag.",
"type": "array",
"items": {
"type": "integer"
},
"context": [
"view",
"edit"
]
}
},
"links": [
{
"rel": "https://api.w.org/action-publish",
"title": "Поточний користувач може опублікувати цей запис.",
"href": "http://wptest.ru/wp-json/wp/v2/posts/{id}",
"targetSchema": {
"type": "object",
"properties": {
"status": {
"type": "string",
"enum": [
"Publish",
"future"
]
}
}
}
},
{
"rel": "https://api.w.org/action-sticky",
"title": "Поточний користувач може зробити цей запис прикріпленим.",
"href": "http://wptest.ru/wp-json/wp/v2/posts/{id}",
"targetSchema": {
"type": "object",
"properties": {
"sticky": {
"type": "boolean"
}
}
}
},
{
"rel": "https://api.w.org/action-assign-author",
"title": "Поточний користувач може змінити автора для цього запису.",
"href": "http://wptest.ru/wp-json/wp/v2/posts/{id}",
"targetSchema": {
"type": "object",
"properties": {
"author": {
"type": "integer"
}
}
}
},
{
"rel": "https://api.w.org/action-assign-categories",
"title": "Поточний користувач може призначати елементи в таксономії категорії.",
"href": "http://wptest.ru/wp-json/wp/v2/posts/{id}",
"targetSchema": {
"type": "object",
"properties": {
"categories": {
"type": "array",
"items": {
"type": "integer"
}
}
}
}
},
{
"rel": "https://api.w.org/action-create-categories",
"title": "Поточний користувач може створювати елементи в таксономії категорії.",
"href": "http://wptest.ru/wp-json/wp/v2/posts/{id}",
"targetSchema": {
"type": "object",
"properties": {
"categories": {
"type": "array",
"items": {
"type": "integer"
}
}
}
}
},
{
"rel": "https://api.w.org/action-assign-tags",
"title": "Поточний користувач може призначати елементи в таксономії post_tag.",
"href": "http://wptest.ru/wp-json/wp/v2/posts/{id}",
"targetSchema": {
"type": "object",
"properties": {
"tags": {
"type": "array",
"items": {
"type": "integer"
}
}
}
}
},
{
"rel": "https://api.w.org/action-create-tags",
"title": "Поточний користувач може створювати елементи в таксономії post_tag.",
"href": "http://wptest.ru/wp-json/wp/v2/posts/{id}",
"targetSchema": {
"type": "object",
"properties": {
"tags": {
"type": "array",
"items": {
"type": "integer"
}
}
}
}
}
]
}
}
Отримання запису
Алгоритм схожий на роботу функції get_post() .
Вид запиту
Доступ: публічний
GET /wp/v2/posts/{id}
Параметри запиту
- id
(обов’язковий) - Унікальний ідентифікатор запису
- context
- Область, у якій виконується запит; визначає поля, присутні у відповіді. Можливо
view ,
embed ,
edit .Типово: view
- password
- Пароль для отримання доступу до захищеного паролем запису.
Приклад запиту
$ curl http://demo.wp-api.org/wp-json/wp/v2/posts/{id}
Приклад запиту на об’єкт запису з ID=1:
https://demo.wp-api.org/wp-json/wp/v2/posts/1
Відповідь:
{
"id":1,
"date":"2017-05-23T06:25:50",
"date_gmt":"2017-05-23T06:25:50",
"guid": {
"rendered":"http://demo.wp-api.org/?p=1"
},
"modified":"2017-05-23T06:25:50",
"modified_gmt":"2017-05-23T06:25:50",
"slug": "hello-world",
"status":"publish",
"type":"post",
"link":"https://demo.wp-api.org/2017/05/23/hello-world/",
"title":{
"rendered":"Hello world!"
},
"content":{
"rendered":"<p>Welcome to <a href="http://wp-api.org/">WP API Demo Sites</a>. start blogging!</p>n",
"protected":false
},
"excerpt":{
"rendered":"<p>Welcome to WP API Demo Sites. Це є вашим першим повідомленням.
"protected":false
},
"author":1,
"featured_media":0,
"comment_status":"open",
"ping_status":"open",
"sticky": false,
"template":"",
"format":"standard",
"meta":[
],
"categories":[
1
],
"tags":[
],
"_links":{
"self":[
{
"href":"https://demo.wp-api.org/wp-json/wp/v2/posts/1"
}
],
"collection":[
{
"href":"https://demo.wp-api.org/wp-json/wp/v2/posts"
}
],
"about":[
{
"href":"https://demo.wp-api.org/wp-json/wp/v2/types/post"
}
],
"author":[
{
"embeddable":true,
"href":"https://demo.wp-api.org/wp-json/wp/v2/users/1"
}
],
"replies":[
{
"embeddable":true,
"href":"https://demo.wp-api.org/wp-json/wp/v2/comments?post=1"
}
],
"version-history":[
{
"href":"https://demo.wp-api.org/wp-json/wp/v2/posts/1/revisions"
}
],
"wp:attachment":[
{
"href":"https://demo.wp-api.org/wp-json/wp/v2/media?parent=1"
}
],
"wp:term":[
{
"taxonomy":"category",
"embeddable":true,
"href":"https://demo.wp-api.org/wp-json/wp/v2/categories?post=1"
},
{
"taxonomy":"post_tag",
"embeddable":true,
"href":"https://demo.wp-api.org/wp-json/wp/v2/tags?post=1"
}
],
"curies":[
{
"name":"wp",
"href":"https://api.w.org/{rel}",
"templated":true
}
]
}
}
Оновлення запису
Алгоритм схожий на роботу функції wp_update_post() .
Вид запиту
Доступ: потрібна авторизація
POST|PUT|PATCH /wp/v2/posts/{id}
Параметри запиту
- id
(обов’язковий) - Унікальний ідентифікатор запису, який потрібно оновити.
- Інші параметри
- Цілком збігаються з параметрами
“Створення запису” .
Приклад запиту
$ curl -X POST http://demo.wp-api.org/wp-json/wp/v2/posts/<id> -d '{"title":"My New Title"}'
Видалення запису
Алгоритм схожий на роботу функції wp_delete_post() .
Вид запиту
Доступ: потрібна авторизація
DELETE /wp/v2/posts/{id}
Параметри запиту
- id
(обов’язковий) - Унікальний ідентифікатор запису, який потрібно видалити.
- force
(логічний) - Видаляти повз кошик, якщо він увімкнений.
true
– Примусове видалення назавжди.Типово: false
Приклад запиту
Видалимо пост 25:
$ curl -X DELETE http://demo.wp-api.org/wp-json/wp/v2/posts/25