How do I fetch all comments per post via WP REST API?

Question

I am busy trying to understand how WP REST API works in combination with React. When I check the documentation of WP REST API, it confuses me a bit.

https://developer.wordpress.org/rest-api/reference/comments/#retrieve-a-comment

For example here, it seems like you have to specifically give the ID of a post in the query to fetch the post. Can we not use a variable for this? If so, how could this be done? And how could we make sure that per post, automatically we also fetch its comments beneath it?

I mean, this gets all of the comments:

https://example.com/wp-json/wp/v2/comments

But it does not let me combine this with the posts. How do we relate them with each other?

Another example:

https://example.com/wp-json/wp/v2/posts?categories=33

Would mean that we you fetch the categories of post with ID = 33, but how can we make this generic? Like https://example.com/wp-json/wp/v2/posts?categories=$GET_POST_ID or so?

0
, , , , Siyah 3 years 2020-04-05T04:50:49-05:00 0 Answers 97 views 0

Leave an answer

Browse
Browse