1

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?

1 Answer 1

0

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}
1
  • That is correct but I think you're approaching your problems in reverse. Apr 14, 2023 at 5:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.