Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

WordPress Rest API not returning all the posts in the website.

Right now im using https://wordpress.org/plugins/rest-api/ plugin for my wordpress website. When I try to call the JSON responce by using "www.mywebsite.com/wp-json/wp/v2/posts" it only returns the JSON data of ten posts. How can I get the JSON data of all the posts in my websit.....??

1 Answer

Adam Mould
Adam Mould
6,292 Points

Hi John,

You can pass arguments to the request URL. So the following would return 50 posts;

www.mywebsite.com/wp-json/wp/v2/posts?per_page=50

Unfortunately the per_page argument must be between 1 (inclusive) and 100 (inclusive). If you have over 100 posts and needed all posts regardless, you'd have to send multiple requests and specify the offset argument correctly to retrieve all posts.

A full list of available arguments can be found in the plugin's Posts API Reference.

Thanks a lot for the Information!!!! I will get back to you if I encounter any hurdles.