Search code examples
wordpresswordpress-rest-api

WordPress - Reply on comments with rest API using version 2


How do I send reply comment on a comment with WordPress rest API of version 2?

I did a lot of search about WordPress rest API of version 2 but I didn't find a proper solution on this.


Solution

  • In WordPress a "reply" is a comment with a parent ID.

    You could add argument "parent" to the comment request.

    If comment is a reply, you just send the comment with the argument "parent" in request. The parent is the ID of the comment replied on.

    In example of insert comment in docs, comment parent is 0 becuse it is the main comment. To insert a reply - you add the id of comment replied on as parent id. https://codex.wordpress.org/Function_Reference/wp_insert_comment