Custom Taxonomy in REST API

Question

I have two custom taxonomies that I use for my posts.

I am trying to retrieve the names from only one of them.

In REST API V2, I do the following:

https://example.com/wp-json/wp/v2/posts/14340/?_embed=wp:term

This embeds the actual names for ALL taxonomies (Categories plus my two custom ones) but I am only interested in the names associated with each post only for one of the custom taxonomies.

Example response:

"_embedded": {
    "wp:term": [
        [
            {
                "id": 2272,
                "link": "https://example.com/category/cat1/",
                "name": "Cat1",
                "slug": "cat1",
                "taxonomy": "category",
                "_links": {
                ....
                }
            }
        ],
        [],
        [
            {
                "id": 1740,
                "link": "https://example.com/custom1/custom-name/",
                "name": "Custom Name",
                "slug": "custom-name",
                "taxonomy": "custom-tax-1",
                "_links": {
                ....
                }
            }
        ],
        [
            {
                "id": 2148,
                "link": "https://example.com/custom2/custom-name-1/",
                "name": "Custom Name 1",
                "slug": "custom-name-1",
                "taxonomy": "custom-tax-2",
                "_links": {
                ....
                }
            },
            {
                "id": 2150,
                "link": "https://example.com/custom2/custom-name-2/",
                "name": "Custom Name 2",
                "slug": "custom-name-2",
                "taxonomy": "custom-tax-2",
                "_links": {
                ....
                }
            }
        ]
    ]
}

So I get back these taxonomies:

  1. category (1 item)
  2. custom-tax-1 (1 item)
  3. custom-tax-2 (2 items)

How can I make it so it only returns values for custom-tax-2?

solved 0
user3542212 2 months 2021-04-14T18:50:33-05:00 0 Answer 0 views 0

Answer ( 1 )

    0
    2021-04-21T15:05:00-05:00

    Figured it out. Just needed to make a call like this to get the values of the custom taxonomy for a specific post:

    https://example.com/wp-json/wp/v2/custom-tax-2?post={id}

    Best answer

Leave an answer

Browse
Browse