Query WordPress dataCustom Tags
Custom Tags
Read more in guide Working with Custom Tags.
These are examples of queries to fetch custom tag taxonomy data.
Taxonomies unmapped to the schema
Retrieve tags with taxonomy "product-tag":
query {
  tags(taxonomy: "product-tag") {
    __typename
 
    ...on Tag {
      count
      description
      id
      name
      slug
      url
    }
    
    ...on GenericTag {
      taxonomy   
      customPostCount
      customPosts {
        __typename
        ...on CustomPost {
          id
          title
        }
      }
    }
  }
}Retrieving tags associated to a custom post
Type GenericCustomPost has field tags, to retrieve the custom tags added to the custom post:
query {
  customPosts(
    filter: { customPostTypes: "product" }
  ) {
    __typename
 
    ... on GenericCustomPost {
      tags(taxonomy: "product-tag") {
        __typename
        id
        name
        taxonomy
      }
    }
  }
}Filtering custom posts by tag
To retrieve the custom posts with given tags, we can use input filter.tags:
query {
  customPostsByTagIDs: customPosts(
    filter: {
      tags: {
        includeBy: {
          ids: [26, 28],
        }
        taxonomy: "product-tag"
      }
    }
  ) {
    id
    title
  }
 
  customPostsByTagSlugs: customPosts(
    filter: {
      tags: {
        includeBy: {
          slugs: ["tango", "rock"]
        }
        taxonomy: "product-tag"
      }
    }
  ) {
    id
    title
  }
}Setting tags on a custom post
Mutation:
mutation {
  setTagsOnCustomPost(
    input: {
      id: 1499, 
      tags: ["api", "development"]
      taxonomy: "tag-taxonomy"
    }
  ) {
    status
    errors {
      __typename
      ... on ErrorPayload {
        message
      }
    }
    customPostID
    customPost {
      tags(taxonomy: "tag-taxonomy") {
        id
      }
      tagNames(taxonomy: "tag-taxonomy")
    }
  }
}Nested mutation:
mutation {
  customPost(by: { id: 1499 }) {
    setTags(
      input: {
        tags: ["api", "development"]
        taxonomy: "tag-taxonomy"
      }
    ) {
      status
      errors {
        __typename
        ... on ErrorPayload {
          message
        }
      }
      customPostID
      customPost {
        tags(taxonomy: "tag-taxonomy") {
          id
        }
        tagNames(taxonomy: "tag-taxonomy")
      }
    }
  }
}Creating, updating and deleting a custom tag
This query creates, updates and deletes tag terms for a custom some-tag-taxonomy tag:
mutation CreateUpdateDeleteTags {
  createTag(input: {
    taxonomy: "some-tag-taxonomy",
    name: "Some name"
    slug: "Some slug"
    description: "Some description"
  }) {
    status
    errors {
      __typename
      ...on ErrorPayload {
        message
      }
    }
    category {
      ...TagData
    }
  }
 
  updateTag(input: {
    id: 1
    taxonomy: "some-tag-taxonomy"
    name: "Some updated name"
    slug: "Some updated slug"
    description: "Some updated description"
  }) {
    status
    errors {
      __typename
      ...on ErrorPayload {
        message
      }
    }
    category {
      ...TagData
    }
  }
 
  deleteTag(input: {
    id: 1
    taxonomy: "some-tag-taxonomy"
  }) {
    status
    errors {
      __typename
      ...on ErrorPayload {
        message
      }
    }
  }
}
 
fragment TagData on Tag {
  id
  name
  slug
  description
}Prev
