无法使用wordpress api v2限制对特定帖子ID的评论
问题描述:
使以下请求返回来自博客的每条评论。它不限于查询参数中的帖子ID。无法使用wordpress api v2限制对特定帖子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
注意如何2500个注释回来,即使该职位ID。
如何更改请求以便只返回特定帖子的评论?
答
使用此
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
做更多的例子查询,如果我做一个GET请求,准确的URL,问题是相同的。超过2500条评论被返回。您可以自行尝试,因为该网站是活的。 –
@DanSafee在一篇文章中超过2500条评论?或者您网站的所有文章? –
它从一开始就返回该网站的所有帖子 –