[wp-trac] [WordPress Trac] #39070: WP-API JS client can't use getCategories for models returned by collections

WordPress Trac noreply at wordpress.org
Sun Dec 4 20:03:27 UTC 2016


#39070: WP-API JS client can't use getCategories for models returned by collections
----------------------------------+-----------------------------
 Reporter:  jesseenterprises      |      Owner:
     Type:  defect (bug)          |     Status:  new
 Priority:  normal                |  Milestone:  Awaiting Review
Component:  REST API              |    Version:  trunk
 Severity:  normal                |   Keywords:
  Focuses:  javascript, rest-api  |
----------------------------------+-----------------------------
 Migrating report from https://github.com/WP-API/client-js/issues/144


 ----

 If I do this:

 {{{
 var postsCollection = new wp.api.collections.Posts();
 postsCollection.fetch();
 }}}

 I'm only seeing the category id returned in the attributes object for each
 post.

 Is there a way to include all category data there? Or from that point,
 when I'm looping over postsCollection, how do I get the category data for
 each post?

 I tried doing this:

 {{{
 postsCollection.each( function( post ) {
     post.getCategories().done( function( postCategories ) {
         // ... do something with the categories.
         // The new post has an single Category: Uncategorized
         console.log( postCategories[0].name );
         // response -> "Uncategorized"
     });
 });
 }}}

 But this is giving me post.getCategories is not a function.

 Any insight here? Basically I'm just trying to find out how to loop over
 posts AND include their categories.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/39070>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list