4

I'm getting started with a project that is making use of Backbone and the WP REST API, but I"m having a little trouble.

Using the built in API JS for models and collections allows me to pretty easily update a post title or content. All I have to do is call:

this.model.set({title: 'New Title'});
this.model.save();

And everything works really well. But for post meta, there doesn't appear to be an easy way to update an entry to the database. Does anyone know how to go about taking a post model in Backbone, and updating it's meta data?

0
var parentId = 96; // the post id
var metaData = new wp.api.collections.PostMeta('', {parent: parentId});
metaData.fetch()
  .done(function(data) {
    var someKey = data.findWhere({key: 'someKey'});
    someKey.set('value', 'newValue');

    someKey.save({parent: parentId});
  });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.