Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress API JSON return limit

Tags:

json

wordpress

This is a simple question regarding Wordpress API /wp-json. I am querying some data filtered with certain category in Wordpress. My questions is how can I control amount of result that gets returned from my Get request... The default returns seems to return around 11 most recent results. Is there any way I can make it return only 1 (most recent), or like 100 posts. What is the minimum and maximum amount I can return. And what is the syntax for it. This is the default request I have:

http://thisismywebsitewherewordpresslives.com/wp-json/posts?fiter[category_name]=Some Category Name I want to query&filter[order]=ASC
like image 754
Anthony Gawon Lee Avatar asked Mar 20 '15 16:03

Anthony Gawon Lee


2 Answers

If you're using v2 of the WordPress REST API, it looks like the current method of controlling the number of results returned is:

website.com/wp-json/wp/v2/posts/?per_page=100

Replace 100 with the desired count.

If you're using a custom post type, replace posts with the custom post type. Also make sure to set 'show_in_rest' => true when configuring the custom post type.

like image 83
apmeyer Avatar answered Oct 11 '22 11:10

apmeyer


Add the filter[posts_per_page] parameter to the query to restrict the number of results returned by the API.

http://thisismywebsitewherewordpresslives.com/wp-json/posts?filter[posts_per_page]=2&fiter[category_name]=Some Category Name I want to query&filter[order]=ASC

The above query should return only 2 results. The list of query parameters are present here https://github.com/WP-API/WP-API/blob/master/docs/routes/routes.md#retrieve-posts

like image 45
Nithish Thomas Avatar answered Oct 11 '22 11:10

Nithish Thomas