Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WP rest api: How to get number of comments

Tags:

json

wordpress

I read all the Wordpress WP rest api document but i did not find how to limit the numbers of comments i want. I tryed. http://mywebsite.com/wp-json/posts/999/comments?filter[comments_per_page]=1

like image 355
Gino Avatar asked Oct 31 '22 19:10

Gino


1 Answers

If you're able to use version 2 of the Rest API, then the endpoint is something like the following:

domain.com/wp-json/wp/v2/comments?post=1&per_page=2

where the post parameter is the ID of the post for which you're retrieving the comments and per_page is how many to show. If you want a list of all comments, and limit them, then:

domain.com/wp-json/wp/v2/comments?per_page=2

You can also append a page parameter to show a different paged value of comments thus:

domain.com/wp-json/wp/v2/comments?post=1&per_page=2&page=3

which would return the 5th and 6th comments (page 3 of comments when there are 2 per page) for the post with an ID of 1

like image 193
RichardTape Avatar answered Nov 15 '22 05:11

RichardTape