发出以下请求将返回博客中的每条评论。它不限于查询参数中的帖子ID。
这是一个错误,还是我做错了什么?
http://anawins.com/wp-json/wp/v2/comments/?post=2986
或
http://anawins.com/wp-json/wp/v2/comments?post=2986
的产率:
HTTP/1.1 200 OK
Server: nginx/1.6.3
Date: Sat, 23 Jul 2016 15:47:47 GMT
Content-Type: application/json; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
X-Powered-By: PHP/5.4.16
Vary: Cookie
Set-Cookie: PHPSESSID=96jsfcdeg8ksnraq5aa3o1a3o7; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: oculus-unknown-switcher=1; expires=Sun, 23-Jul-2017 15:47:46 GMT
Set-Cookie: oculus-unknown-switcher=1; expires=Sun, 23-Jul-2017 15:47:46 GMT
Set-Cookie: wp_woocommerce_session_d65537f626aa4d41876f80145673898a=a4bbe5c1e08f80685e3bf383595f1ce4%7C%7C1469461666%7C%7C1469458066%7C%7C92bf547bd7e641385bb561b739e1c87a; expires=Mon, 25-Jul-2016 15:47:46 GMT; path=/
X-Content-Type-Options: nosniff
Access-Control-Expose-Headers: X-WP-Total, X-WP-TotalPages
Access-Control-Allow-Headers: Authorization
X-WP-Total: 2549
X-WP-TotalPages: 255
Link: <http://anawins.com/wp-json/wp/v2/comments?q=%2Fwp-json%2Fwp%2Fv2%2Fcomments%2F%3Fpost%3D2986&context=view&page=2>; rel="next"
Allow: GET
请注意即使有帖子ID,也会有2500条评论回来。
如何更改请求以便仅返回特定帖子的评论?
答案 0 :(得分:0)
使用此
http://anawins.com/wp-json/wp/v2/comments?post=1
结果将是
[
{
"id": 1,
"post": 1,
"parent": 0,
"author": 0,
"author_name": "Mr WordPress",
"author_url": "https://wp-api.org/",
"date": "2016-05-10T07:25:45",
"date_gmt": "2016-05-10T07:25:45",
"content": {
"rendered": "<p>Hi, this is a comment.<br />\nTo delete a comment, just log in and view the post's comments. There you will have the option to edit or delete them.</p>\n"
},
"link": "https://demo.wp-api.org/2016/05/10/hello-world/#comment-1",
"status": "approved",
"type": "comment",
"author_avatar_urls": {
"24": "https://secure.gravatar.com/avatar/?s=24&d=mm&r=g",
"48": "https://secure.gravatar.com/avatar/?s=48&d=mm&r=g",
"96": "https://secure.gravatar.com/avatar/?s=96&d=mm&r=g"
},
"_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"
}
]
}
}
]
您可以在WP Demo Rest API
处执行更多示例查询