Comments

These routes allow you to retrieve/create/update/delete comments.

Possible routes (endpoints described below):

/wp/v2/comments         // works with all comments
/wp/v2/comments/{ID}    // works with the specified comment instead of {ID}

Controller class: WP_REST_Comments_Controller{}

Resource schema

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

Parameter Context Description
id
number
view, edit, embed ID of the comment.
Read-only.
author
number
view, edit, embed Identifier (ID) of the comment author, if they were authenticated.
author_email
string
edit Email address of the comment author.
author_ip
string
edit IP address of the comment author.
author_name
string
view, edit, embed Display name of the comment author.
author_url
string
view, edit, embed URL of the comment author’s website.
author_user_agent
string
edit User agent of the comment author.
content
object
view, edit, embed Content of the comment.
date
string
view, edit, embed Date of the comment publication in the site's timezone.
date_gmt
string/datetime
view, edit Date of the comment publication, as GMT.
link
string
view, edit, embed URL of the comment.
Read-only.
parent
number
view, edit, embed ID of the parent comment.
post
number
view, edit ID of the post to which the comment is attached.
status
string
view, edit Status of the comment (approve, spam, etc.).
type
string
view, edit, embed Type of the comment.
Read-only.
author_avatar_urls
object
view, edit, embed URL of the comment author's avatar.
Read-only.
meta
object
view, edit Meta-fields of the comment.

wp/v2/comments

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/comments
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,
                    "description": "Ограничить выборку комментариями назначенными определенному ID пользователя. Требует авторизации.",
                    "type": "array",
                    "items": {
                        "type": "integer"
                    }
                },
                "author_exclude": {
                    "required": false,
                    "description": "Убедиться что выборка исключает комментарии назначенные определенному ID пользователя. Требует авторизации.",
                    "type": "array",
                    "items": {
                        "type": "integer"
                    }
                },
                "author_email": {
                    "required": false,
                    "description": "Ограничить выборку до имеющей определённый e-mail автора. Требует авторизации.",
                    "type": "string"
                },
                "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"
                    }
                },
                "offset": {
                    "required": false,
                    "description": "Сдвиг выборки на определенное число объектов.",
                    "type": "integer"
                },
                "order": {
                    "required": false,
                    "default": "desc",
                    "enum": [
                        "asc",
                        "desc"
                    ],
                    "description": "Упорядочить сортировку атрибута по возрастанию или убыванию.",
                    "type": "string"
                },
                "orderby": {
                    "required": false,
                    "default": "date_gmt",
                    "enum": [
                        "date",
                        "date_gmt",
                        "id",
                        "include",
                        "post",
                        "parent",
                        "type"
                    ],
                    "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"
                    }
                },
                "post": {
                    "required": false,
                    "default": [],
                    "description": "Ограничить выборку комментариями с назначенными определенными ID записей.",
                    "type": "array",
                    "items": {
                        "type": "integer"
                    }
                },
                "status": {
                    "required": false,
                    "default": "approve",
                    "description": "Ограничить выборку комментариями с определенным статусом. Требует авторизации. ",
                    "type": "string"
                },
                "type": {
                    "required": false,
                    "default": "comment",
                    "description": "Ограничить выборку комментариями с определенным типом. Требует авторизации.",
                    "type": "string"
                },
                "password": {
                    "required": false,
                    "description": "Пароль для записи, если она защищена паролем.",
                    "type": "string"
                }
            }
        },
        {
            "methods": [
                "POST"
            ],
            "args": {
                "author": {
                    "required": false,
                    "description": "ID объекта пользователя, если автор - пользователь.",
                    "type": "integer"
                },
                "author_email": {
                    "required": false,
                    "description": "Адрес e-mail автора объекта.",
                    "type": "string"
                },
                "author_ip": {
                    "required": false,
                    "description": "IP адрес автора объекта.",
                    "type": "string"
                },
                "author_name": {
                    "required": false,
                    "description": "Отображаемое имя для автора объекта.",
                    "type": "string"
                },
                "author_url": {
                    "required": false,
                    "description": "URL для автора объекта.",
                    "type": "string"
                },
                "author_user_agent": {
                    "required": false,
                    "description": "Клиентское приложение для автора объекта.",
                    "type": "string"
                },
                "content": {
                    "required": false,
                    "description": "Содержимое объекта.",
                    "type": "object"
                },
                "date": {
                    "required": false,
                    "description": "Дата публикации объекта, по временной зоне сайта.",
                    "type": "string"
                },
                "date_gmt": {
                    "required": false,
                    "description": "Время публикации объекта, по GMT.",
                    "type": "string"
                },
                "parent": {
                    "required": false,
                    "default": 0,
                    "description": "ID родителя объекта.",
                    "type": "integer"
                },
                "post": {
                    "required": false,
                    "default": 0,
                    "description": "ID ассоциированного объекта записи.",
                    "type": "integer"
                },
                "status": {
                    "required": false,
                    "description": "Состояние объекта.",
                    "type": "string"
                },
                "meta": {
                    "required": false,
                    "description": "Мета поля.",
                    "type": "object"
                }
            }
        }
    ],
    "schema": {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "title": "comment",
        "type": "object",
        "properties": {
            "id": {
                "description": "Уникальный идентификатор для объекта.",
                "type": "integer",
                "context": [
                    "view",
                    "edit",
                    "embed"
                ],
                "readonly": true
            },
            "author": {
                "description": "ID объекта пользователя, если автор - пользователь.",
                "type": "integer",
                "context": [
                    "view",
                    "edit",
                    "embed"
                ]
            },
            "author_email": {
                "description": "Адрес e-mail автора объекта.",
                "type": "string",
                "format": "email",
                "context": [
                    "edit"
                ]
            },
            "author_ip": {
                "description": "IP адрес автора объекта.",
                "type": "string",
                "format": "ip",
                "context": [
                    "edit"
                ]
            },
            "author_name": {
                "description": "Отображаемое имя для автора объекта.",
                "type": "string",
                "context": [
                    "view",
                    "edit",
                    "embed"
                ]
            },
            "author_url": {
                "description": "URL для автора объекта.",
                "type": "string",
                "format": "uri",
                "context": [
                    "view",
                    "edit",
                    "embed"
                ]
            },
            "author_user_agent": {
                "description": "Клиентское приложение для автора объекта.",
                "type": "string",
                "context": [
                    "edit"
                ]
            },
            "content": {
                "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
                    }
                }
            },
            "date": {
                "description": "Дата публикации объекта, по временной зоне сайта.",
                "type": "string",
                "format": "date-time",
                "context": [
                    "view",
                    "edit",
                    "embed"
                ]
            },
            "date_gmt": {
                "description": "Время публикации объекта, по GMT.",
                "type": "string",
                "format": "date-time",
                "context": [
                    "view",
                    "edit"
                ]
            },
            "link": {
                "description": "URL объекта.",
                "type": "string",
                "format": "uri",
                "context": [
                    "view",
                    "edit",
                    "embed"
                ],
                "readonly": true
            },
            "parent": {
                "description": "ID родителя объекта.",
                "type": "integer",
                "context": [
                    "view",
                    "edit",
                    "embed"
                ],
                "default": 0
            },
            "post": {
                "description": "ID ассоциированного объекта записи.",
                "type": "integer",
                "context": [
                    "view",
                    "edit"
                ],
                "default": 0
            },
            "status": {
                "description": "Состояние объекта.",
                "type": "string",
                "context": [
                    "view",
                    "edit"
                ]
            },
            "type": {
                "description": "Тип комментария для объекта.",
                "type": "string",
                "context": [
                    "view",
                    "edit",
                    "embed"
                ],
                "readonly": true
            },
            "author_avatar_urls": {
                "description": "URL аватары автора объекта.",
                "type": "object",
                "context": [
                    "view",
                    "edit",
                    "embed"
                ],
                "readonly": true,
                "properties": {
                    "24": {
                        "description": "URL аватары с размером изображения в 24 пикселей.",
                        "type": "string",
                        "format": "uri",
                        "context": [
                            "embed",
                            "view",
                            "edit"
                        ]
                    },
                    "48": {
                        "description": "URL аватары с размером изображения в 48 пикселей.",
                        "type": "string",
                        "format": "uri",
                        "context": [
                            "embed",
                            "view",
                            "edit"
                        ]
                    },
                    "96": {
                        "description": "URL аватары с размером изображения в 96 пикселей.",
                        "type": "string",
                        "format": "uri",
                        "context": [
                            "embed",
                            "view",
                            "edit"
                        ]
                    }
                }
            },
            "meta": {
                "description": "Мета поля.",
                "type": "object",
                "context": [
                    "view",
                    "edit"
                ],
                "properties": []
            }
        }
    },
    "_links": {
        "self": "http://wp-test.ru/wp-json/wp/v2/comments"
    }
}

List of comments

The algorithm is similar to the function get_comments().

Request type

GET /wp/v2/comments

Request parameters

context
The area in which the request is made; defines the fields present in the response.
Might be: view, embed, edit
Default: view
page
The current pagination page.
Default: 1
per_page
The maximum number of items returned in the result.
Default: 10
search
Limit results to those matching the string.
after
Limit the response to comments published after the specified date, corresponding to ISO8601.
before
Limit the response to comments published before the specified date, corresponding to ISO8601.
author
Indicates which authors' comments (their IDs) should be returned. Authorization required.
author_exclude
Indicates which authors' comments (their IDs) should not be returned. Authorization required.
author_email
Indicates which authors' comments (their email addresses) should be returned. Authorization required.
exclude
Excludes comments by ID.
include
Shows only the specified comments. IDs must be provided.
offset
Offset the result set by the specified number.
orderby
By which field to sort?
Might be: date, date_gmt, id, include, post, parent, type
Default: date_gmt
order
How to sort?
Might be: asc, desc
Default: desc
status
Limit the selection by one status or multiple. Authorization required.
Default: approve
parent
Limit the selection based on the ID of the parent comment or comments.
parent_exclude
Excludes comments based on the ID of the parent comment or comments.
post:
Limit the selection based on the ID of the post (or posts) to which the comments are attached.
type
Limit the selection based on the type of comment. Authorization required.
Default: comment
password
Password for the post if it is password-protected.

Example request

Links are functional, you can open them in a browser and see the result.

1) Request to get an array of all comments:

https://demo.wp-api.org/wp-json/wp/v2/comments/

An array of objects will be returned, where each comment object is similar to what is described in the "Get comment" section:

[
	{
	... comment data <id> ...
	},
	{
	... comment data <id> ...
	},
	{
	... comment data <id> ...
	}
]

Creating a comment

The algorithm is similar to the function wp_insert_comment().

Request type

Access: authorization required

POST /wp/v2/comments

Request parameters

author
ID of the user if they are registered.
author_email
User's email address.
author_ip
User's IP address.
author_name
Display name of the comment author.
author_url
URL of the comment author's website.
author_user_agent
User agent of the comment author.
content
Content of the comment.
date
Date of the comment publication in the site's timezone.
date_gmt
Date of the comment publication, as GMT.
parent
ID of the parent comment.
post
ID of the post to which the comment will be left.
status
Status of the comment.
meta
Meta-fields of the comment.

Example request

POST http://example.com/wp-json/wp/v2/comments/[email protected]&content=Great article

wp/v2/comments/{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/comments/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"
                },
                "author": {
                    "required": false,
                    "description": "ID объекта пользователя, если автор - пользователь.",
                    "type": "integer"
                },
                "author_email": {
                    "required": false,
                    "description": "Адрес e-mail автора объекта.",
                    "type": "string"
                },
                "author_ip": {
                    "required": false,
                    "description": "IP адрес автора объекта.",
                    "type": "string"
                },
                "author_name": {
                    "required": false,
                    "description": "Отображаемое имя для автора объекта.",
                    "type": "string"
                },
                "author_url": {
                    "required": false,
                    "description": "URL для автора объекта.",
                    "type": "string"
                },
                "author_user_agent": {
                    "required": false,
                    "description": "Клиентское приложение для автора объекта.",
                    "type": "string"
                },
                "content": {
                    "required": false,
                    "description": "Содержимое объекта.",
                    "type": "object"
                },
                "date": {
                    "required": false,
                    "description": "Дата публикации объекта, по временной зоне сайта.",
                    "type": "string"
                },
                "date_gmt": {
                    "required": false,
                    "description": "Время публикации объекта, по GMT.",
                    "type": "string"
                },
                "parent": {
                    "required": false,
                    "description": "ID родителя объекта.",
                    "type": "integer"
                },
                "post": {
                    "required": false,
                    "description": "ID ассоциированного объекта записи.",
                    "type": "integer"
                },
                "status": {
                    "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"
                },
                "password": {
                    "required": false,
                    "description": "Пароль для родительской записи комментария (если запись защищена паролем).",
                    "type": "string"
                }
            }
        }
    ],
    "schema": {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "title": "comment",
        "type": "object",
        "properties": {
            "id": {
                "description": "Уникальный идентификатор для объекта.",
                "type": "integer",
                "context": [
                    "view",
                    "edit",
                    "embed"
                ],
                "readonly": true
            },
            "author": {
                "description": "ID объекта пользователя, если автор - пользователь.",
                "type": "integer",
                "context": [
                    "view",
                    "edit",
                    "embed"
                ]
            },
            "author_email": {
                "description": "Адрес e-mail автора объекта.",
                "type": "string",
                "format": "email",
                "context": [
                    "edit"
                ]
            },
            "author_ip": {
                "description": "IP адрес автора объекта.",
                "type": "string",
                "format": "ip",
                "context": [
                    "edit"
                ]
            },
            "author_name": {
                "description": "Отображаемое имя для автора объекта.",
                "type": "string",
                "context": [
                    "view",
                    "edit",
                    "embed"
                ]
            },
            "author_url": {
                "description": "URL для автора объекта.",
                "type": "string",
                "format": "uri",
                "context": [
                    "view",
                    "edit",
                    "embed"
                ]
            },
            "author_user_agent": {
                "description": "Клиентское приложение для автора объекта.",
                "type": "string",
                "context": [
                    "edit"
                ]
            },
            "content": {
                "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
                    }
                }
            },
            "date": {
                "description": "Дата публикации объекта, по временной зоне сайта.",
                "type": "string",
                "format": "date-time",
                "context": [
                    "view",
                    "edit",
                    "embed"
                ]
            },
            "date_gmt": {
                "description": "Время публикации объекта, по GMT.",
                "type": "string",
                "format": "date-time",
                "context": [
                    "view",
                    "edit"
                ]
            },
            "link": {
                "description": "URL объекта.",
                "type": "string",
                "format": "uri",
                "context": [
                    "view",
                    "edit",
                    "embed"
                ],
                "readonly": true
            },
            "parent": {
                "description": "ID родителя объекта.",
                "type": "integer",
                "context": [
                    "view",
                    "edit",
                    "embed"
                ],
                "default": 0
            },
            "post": {
                "description": "ID ассоциированного объекта записи.",
                "type": "integer",
                "context": [
                    "view",
                    "edit"
                ],
                "default": 0
            },
            "status": {
                "description": "Состояние объекта.",
                "type": "string",
                "context": [
                    "view",
                    "edit"
                ]
            },
            "type": {
                "description": "Тип комментария для объекта.",
                "type": "string",
                "context": [
                    "view",
                    "edit",
                    "embed"
                ],
                "readonly": true
            },
            "author_avatar_urls": {
                "description": "URL аватары автора объекта.",
                "type": "object",
                "context": [
                    "view",
                    "edit",
                    "embed"
                ],
                "readonly": true,
                "properties": {
                    "24": {
                        "description": "URL аватары с размером изображения в 24 пикселей.",
                        "type": "string",
                        "format": "uri",
                        "context": [
                            "embed",
                            "view",
                            "edit"
                        ]
                    },
                    "48": {
                        "description": "URL аватары с размером изображения в 48 пикселей.",
                        "type": "string",
                        "format": "uri",
                        "context": [
                            "embed",
                            "view",
                            "edit"
                        ]
                    },
                    "96": {
                        "description": "URL аватары с размером изображения в 96 пикселей.",
                        "type": "string",
                        "format": "uri",
                        "context": [
                            "embed",
                            "view",
                            "edit"
                        ]
                    }
                }
            },
            "meta": {
                "description": "Мета поля.",
                "type": "object",
                "context": [
                    "view",
                    "edit"
                ],
                "properties": []
            }
        }
    }
}

Getting a comment

The algorithm is similar to the function get_comment().

Request type

Access: public

GET /wp/v2/comments/{id}

Request parameters

id (required)
Unique identifier of the comment. Specified in the route.
context
The area in which the request is made; defines the fields present in the response. Might be view, embed, edit.
Default: view
password
Password to access the protected post, the comments of which need to be retrieved.

Example request

$ curl http://demo.wp-api.org/wp-json/wp/v2/comments/{id}

Example request for the comment object with ID=1:

https://demo.wp-api.org/wp-json/wp/v2/comments/1

Response:

{
	"id": 1,
	"post": 1,
	"parent": 0,
	"author": 0,
	"author_name": "A WordPress Commenter",
	"author_url": "http://wp-api.org/",
	"date": "2017-05-23T06:25:50",
	"date_gmt": "2017-05-23T06:25:50",
	"content": {
		"rendered": "<p>Hi, this is a comment.<br />\nTo get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.<br />\nCommenter avatars come from <a href=\"https://gravatar.com\">Gravatar</a>.</p>\n"
	},
	"link": "https://demo.wp-api.org/2017/05/23/hello-world/#comment-1",
	"status": "approved",
	"type": "comment",
	"author_avatar_urls": {
		"24": "https://secure.gravatar.com/avatar/d7a973c7dab26985da5f961be7b74480?s=24&d=mm&r=g",
		"48": "https://secure.gravatar.com/avatar/d7a973c7dab26985da5f961be7b74480?s=48&d=mm&r=g",
		"96": "https://secure.gravatar.com/avatar/d7a973c7dab26985da5f961be7b74480?s=96&d=mm&r=g"
	},
	"meta": [],
	"_links": {
		"self": [
			{
				"href": "https://demo.wp-api.org/wp-json/wp/v2/comments/1"
			}
		],
		"collection": [
			{
				"href": "https://demo.wp-api.org/wp-json/wp/v2/comments"
			}
		],
		"up": [
			{
				"embeddable": true,
				"post_type": "post",
				"href": "https://demo.wp-api.org/wp-json/wp/v2/posts/1"
			}
		],
		"children": [
			{
				"href": "https://demo.wp-api.org/wp-json/wp/v2/comments?parent=1"
			}
		]
	}
}

Updating a comment

The algorithm is similar to the function wp_update_comment().

Request type

Access: authorization required

POST /wp/v2/comments/{id}

Request parameters

id
ID of the comment to be updated. Specified in the route.
author
ID of the user if they are registered.
author_email
User's email address.
author_ip
User's IP address.
author_name
Display name of the comment author.
author_url
URL of the comment author's website.
author_user_agent
User agent of the comment author.
content
Content of the comment.
date
Date of the comment publication in the site's timezone.
date_gmt
Date of the comment publication, as GMT.
parent
ID of the parent comment.
post
ID of the post to which the comment will be left.
status
Status of the comment.
meta
Meta-fields of the comment.

Example request

Update the content of the comment with ID=1:

POST http://example.com/wp-json/wp/v2/comments/?id=1&content=Good article

Deleting a comment

The algorithm is similar to the function wp_delete_comment().

Request type

Access: authorization required

DELETE /wp/v2/comments/{id}

Request parameters

id
ID of the comment to be deleted. Specified in the route.
force
Force deletion. If you want to delete the comment without moving it to the trash, set to true.
Default: false
password
Password to access the protected post, the comments of which need to be deleted.

Example request

$ curl -X DELETE http://demo.wp-api.org/wp-json/wp/v2/comments/<id>