WP-API/client-js

wp.api.models.PostMeta is not a constructor

Maden-maxi opened this issue · 4 comments

When I trying get PostMeta, i get an error Uncaught TypeError: wp.api.models.PostMeta is not a constructor

wp.api.loadPromise.done(function () {
                            var metaData = new wp.api.models.PostMeta('', {parent:1});
                            metaData.fetch();
                            console.log(metaData);
                        });

please response me how can i retrive postmeta particular post using Backbone client-js

+1 Having this same issue/question

Not sure if this is the intended work around, but I found this in the manual: https://developer.wordpress.org/reference/functions/register_rest_field/

If you follow the example provided in the comments (change post-meta-fields to post_meta_fields) you get:

post = new wp.api.models.Post({id: 1});
post.fetch();
post.attributes.post_meta_fields >> Object

@bit9labs @Maden-maxi you need to include the ID of the post that you want as the parent:

var metaData = new wp.api.models.PostMeta('', { parent:{ POST_ID } } );
metaData.fetch();

@bit9labs @Maden-maxi thanks for the feedback -

Closing this in favor of https://core.trac.wordpress.org/ticket/41055 so we can work on this in core.