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

admin2025-01-07  6

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  404 (Not Found)

Trying to sync the collection also fails.

Any thoughts? Thanks!

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!

Share Improve this question edited Feb 19, 2016 at 21:17 pdme asked Feb 19, 2016 at 21:07 pdmepdme 2922 gold badges5 silver badges14 bronze badges 1
  • Posted an answer here stackoverflow.com/a/50397449/1654250 if you're interested – Craig Wayne Commented May 18, 2018 at 11:21
Add a comment  | 

1 Answer 1

Reset to default 0

Ok, that was quick.

Pass in the parent id, and it works.

someKey.save({parent: parentId});
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736258827a543.html

最新回复(0)