Access checks with custom REST endpoints and backbone

The issue was I overrode the Backbone.sync method only in Backbone.Model. When Backbone fetches the initial data (GET) it is using the sync method in Backbone.collections. So I need to override the sync in Backbone.Collections: app.Collection = Backbone.Collection.extend({ sync: function( method, model, options ){ return Backbone.sync(method, this, jQuery.extend( options, { beforeSend: function (xhr) { xhr.setRequestHeader( … Read more

URL issue retrieving Custom Post Types using Backbone JS API

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> … Read more

wp-api Backbone JS Client fetch options

Thanks @sallyCJ for fixing my error ! Here’s some examples for WP-API backbone JS client. It may help others : Fetch post of a certain author and category : var filteredPosts = new wp.api.collections.Posts(); authorsPosts.fetch({ data: { author: currentUserId, categories: 42 } }).then( posts => { for(const post of posts){ //do stuff with each post … Read more