WP-API + JS Backbone client - how to update post meta

Using the WP API and Backbone-based JS client, I'm trying to update a post's metadata as follows:

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();
  });

Everything works fine until the calling of save(), which throws the following error:

PUT http://example.org/wp-json/wp/v2/posts/undefined/meta/1901 404 (Not Found)

Trying to sync the collection also fails.

Any thoughts? Thanks!

Topic wp-api backbone plugin-json-api rest-api post-meta Wordpress

Category Web


Ok, that was quick.

Pass in the parent id, and it works.

someKey.save({parent: parentId});

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.