MG Blogstore fetches all posts from the WordPress REST API. It can get one page of posts first, give you an opportunity to do something with those posts, and then make recursive calls to the API for the rest of the posts.
Only the post
post type and its categories are supported, currently. It assumes REST API v2. There are a few configuration options, with more on the roadmap.
<script src="mg-blogstore.js"></script>
var blogStore = new MGBlogStore();
blogStore
.getFirstPage()
.then(function(store) {
// do something with the first page of posts
// you access store.posts and store.categories here
return store.getAllPages(); // begin recursively getting more posts
})
.then(function(store) {
// do something when all posts have been retrieved
});
Your MGBlogstore
instance has access to:
.posts
: an array of all the posts in the store at the given moment..categories
: an array of all the categories (max 100).
You can tell MG Blogstore what base URL to use and how many posts per page you want. You can also pass a custom query string that will be appended to every request (for example if you were using the REST API – Filter Fields plugin).
var blogStore = new MGBlogStore({
baseURL: '/wp-json/wp/v2', // default
perPag
589A
e: 30,
customQuery: 'fields=id,title,link,date,excerpt.rendered,categories'
});