Actually, you don’t have to extend the Post
model (wp.api.models.Post
) or Posts
collection (wp.api.collections.Posts
) because the documentation says:
you will get new models and collections when you add REST API support to your custom post type
And that means, your custom post type will be automatically added to the wp.api.models
and wp.api.collections
list, i.e. wp.api.models.<key>
and wp.api.collections.<key>
whereby <key>
is the post type slug in camel case. So in your case, the key would be Pronews
— or ProNews
if the post type was pro-news
.
Therefore, all you need to do to get access to the model/collection (or simply put, posts) is:
// Access one model (a single post). ID is required.
const post = new wp.api.models.Pronews( { id: 57 } );
// Access a collection (multiple models/posts).
const posts = new wp.api.collections.Pronews();
Easy, eh? 🙂 ( And if you want, you may extend your post type’s model/collection.. e.g. const ProPost = wp.api.models.Pronews.extend( ... )
)