To start I've been searching through several questions and documentation pieces but it seems with WordPress' v2
many of the old questions are no longer valid. What I am trying to do is get all posts or a singular post from a category in Postman instead of the common returned 10 posts without having to modify the API in functions.php.
tldr
I started with referencing the REST API Handbook and reviewing the schema I saw categories
and I can return the 10 latest categories using:
http://foobar.com/wp-json/wp/v2/posts/categories_name=hello
referencing the arguments I see per_page
so I tried:
http://foobar.com/wp-json/wp/v2/posts/categories_name=hello?per_page=1
and it returns 10 posts from the category hello
so I modified and tried:
http://foobar.com/wp-json/wp/v2/posts/categories_name=hello&per_page=1
and I get an error returned:
{ "code": "rest_invalid_param", "message": "Invalid parameter(s): per_page", "data": { "status": 400, "params": { "per_page": "per_page is not of type integer." } } }
Searching through Google I see How to retrieve a list of categories/ tag in Wordpress REST API but the answers are based on v1
.
Trying Wordpress API JSON return limit I use:
http://foobar.com/wp-json/wp/v2/posts/?per_page=1
and I get a singular post so I modified my attempt to:
http://foobar.com/wp-json/wp/v2/posts/?per_page=1$categories_name=hello
It ignores the category type and returns the latest post. Reading Get more than 10 posts in a specific category with the WordPress API I pulled the ID of a category (4) after using:
http://foobar.com/wp-json/wp/v2/categories
then coded:
http://foobar.com/wp-json/wp/v2/posts/?categories=4&per_page=1
and I get:
{ "code": "rest_invalid_param", "message": "Invalid parameter(s): per_page", "data": { "status": 400, "params": { "per_page": "per_page is not of type integer." } } }
I thought I might be able to use -1
similar to the development of a theme but I get an error.
Other references I read are:
- WP REST API - Retrieve content from page
- WP REST API Category
Found this Since filter has been removed, how to get posts by category slug with same schema as v2/posts? after reading Search post by categories Wordpress WP-API
After reviewing the documentation on Pagination it seems to only work with the post
and not any category
. I can only get more than 10 posts if I use /wp-json/wp/v2/posts?per_page=20
, too.
Question
When calling a site's WP API how can I control the per_page
return of a category wether it be 1 post or all posts?