I am working on a web app in PHP that must display recent blog posts of a specific category from a separate WordPress site. We are accessing these posts via the REST API. When I use the categories
argument, I get a 400 error. Without the categories
argument (and with all other endpoints I've tried), I get a successful response.
- The posts are being requested from a site running WordPress 5.2.1.
- For now, I am just accessing the endpoints via my browser, and viewing the JSON returned there.
- I am using the endpoint:
https://itherapy.com/wp-json/wp/v2/posts?categories=60
. - There are 43 published / public posts in the posts category with the id of 60.
- Even if I specify the additional arguments of
per_page
andpage
(for example, likehttps://itherapy.com/wp-json/wp/v2/posts?categories=60&per_page=1&page=1
), I get the same error. By removing thecategories
argument (like this:https://itherapy.com/wp-json/wp/v2/posts?per_page=2&page=2
), the other arguments work (ie, I get 2 posts, offset by 2 posts), but this is for ALL posts. That is expected, but why might thecategories
argument be breaking my request?
I can submit similar requests to the WordPress Rest API demo site, like so: https://demo.wp-api.org/wp-json/wp/v2/posts?categories=11
, and all of the posts from category 11 are returned. the same request made from my domain fails.
The endpoint I am trying to access data from is:
https://itherapy.com/wp-json/wp/v2/posts?categories=60
The error message I am getting back is:
{
"code": "rest_post_invalid_page_number",
"message": "The page number requested is larger than the number of pages available.",
"data": {
"status": 400
}
}