Skip to content
This repository was archived by the owner on Sep 24, 2018. It is now read-only.
This repository was archived by the owner on Sep 24, 2018. It is now read-only.

Getting terms by post id doesn't work #1383

Closed

Description

@michaelperrin

When calling, wp/v2/posts/1 (for instance), the following links are returned in the JSON response:

"_links": {
    "http://v2.wp-api.org/term": [
        {
            "embeddable": true, 
            "href": "http://.../wp/v2/terms/category?post=1", 
            "taxonomy": "category"
        }, 
       // ...
    ]
}

But when calling wp/v2/terms/category?post=1, all the available categories are returned instead of just the ones of post of id 1 in this example.

Activity

  1. jdolan commented on Jul 6, 2015

    @jdolan
    Contributor

    Yea, I ran into this the other day as well. This part of the code was not updated to coincide with how terms are associated currently. Try /wp/v2/posts/{post_id}/terms/{taxonomy_slug}, e.g. /wp/v2/posts/1/terms/category.

  2. michaelperrin commented on Jul 6, 2015

    @michaelperrin
    Author

    @jdolan Thanks, that's exactly what I was looking for! So the problem is more about the related links in the "get post" response.

  3. jdolan commented on Jul 6, 2015

    @jdolan
    Contributor

    Correct. Your bug report is valid -- but at least hopefully you're unblocked now :)

  4. rachelbaker commented on Jul 6, 2015

    @rachelbaker
    Member

    Looks like we removed the ability to pass the post parameter to the terms controller when we added the posts/{id}/terms routes in #1216.

    According to 1ca5182 from @joehoyle this was done to "make it easier". I believe the intent here was to only allowing the post terms to be queried from one endpoint instead of two different endpoints.

    @michaelperrin Do you have any issues with using the `/wp/v2/posts/{id}/terms/{slug} route instead?

  5. michaelperrin commented on Jul 6, 2015

    @michaelperrin
    Author

    @rachelbaker I don't mind at all! I actually prefer the new syntax, thanks for asking!

    It's just that the _links entries should be updated accordingly as it is a bit misleading for now.

  6. jdolan commented on Jul 6, 2015

    @jdolan
    Contributor

    @rachelbaker {slug} or {rest_base}? More confusion around this often duplicate, sometimes confusing rest_base property (#1381). It really should be dropped in favor of slug. It's hijacking the purpose that slug was designed for just to work around the subjective idea that "post_tag" is "ugly."

  7. dev-xiligroup commented on Jul 10, 2015

    @dev-xiligroup

    After beginning tests with REST v2-beta3 this week, making (updating REST v1) a demo HTML5 app with framework7 (listing posts and displaying one each post), I encountered these issues to recover terms of selected terms/taxonomies.
    Route like /wp/v2/posts/{id}/terms/{slug} works (but is not yet in the JSON response)
    The _links response is with a link/url indexes for terms response of route ‘/wp-json/wp/v2/posts’.
    But, my question is about denomination of index of the terms response ? why use an index named like an URL ‘http://v2.wp-api.org/term’ ? In javascript, it is not very easy to manipulate the object after parsing (JSON.parse). To find the array, a var (with value with this link) must be used to work with the results and this index. Example:
    var term_series = “http://v2.wp-api.org/term”; … console.log(JSON.stringify( this._links[term_series] )); …

  8. michaelperrin commented on Aug 6, 2015

    @michaelperrin
    Author

    Thanks @rachelbaker !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      Sponsor
      SponsoredKunjungi sekarang
      Promo