I am using an AngularJS application with WordPress backend. I am able to retrieve comments using WP REST API v2., using the following url
/wp-json/wp/v2/comments?post=1324
But is there a way to post comments in WP REST API v2. I was unable to find anything in documentation. Thanks.
I am using an AngularJS application with WordPress backend. I am able to retrieve comments using WP REST API v2., using the following url
/wp-json/wp/v2/comments?post=1324
But is there a way to post comments in WP REST API v2. I was unable to find anything in documentation. Thanks.
Share Improve this question asked Jan 13, 2016 at 19:30 MerlinMerlin 511 gold badge1 silver badge3 bronze badges 2- In the documentation there is a section titled "Create a comment". You can start there and come back if you have problems to use it. – cybmeta Commented Jan 14, 2016 at 7:20
- The REST endpoint for comments is inconsistent in that the schema for content is different on the outgoing (GET side) vs. incoming (POST/PUT). When you read you get an object with raw/rendered properties. When you add/update a comment you are expected to provide a plain string for the content. – kodbuse Commented Aug 14, 2016 at 0:20
3 Answers
Reset to default 5Similar problem, I was getting back:
{"code":"rest_comment_login_required","message":"Sorry, you must be logged in to comment.","data":{"status":401}}
Looking for that code 'rest_comment_login_required' this is one of the first results: WP_REST_Comments_Controller::create_item_permissions_check.
So from v4.7.0 there is a filter called 'rest_allow_anonymous_comments' returning false by default. So you cannot comment by default even though your Wordpress settings indicate otherwise.
You can turn it back on by adding:
function filter_rest_allow_anonymous_comments() {
return true;
}
add_filter('rest_allow_anonymous_comments','filter_rest_allow_anonymous_comments');
Take a look at the comment docs - http://v2.wp-api/reference/comments/
And the following syntax:
https://www.example/wp-json/wp/v2/comments?author=Your%20Name%20Here&[email protected]&author_name=Your%20Name%20Here&content=Your%20Comment%20Here&post=1604252
Here you go: http://www.contradodigital/2016/04/06/post-comments-wordpress-rest-api-version-2/
Just had to do this myself, the documentation in the official WordPress API v2 isn't the best at the minute.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744787164a4593695.html
评论列表(0条)