Working with Custom Tags
We can add tags to posts in WordPress (i.e. using the taxonomy with name "post_tag"
). This is already mapped in the GraphQL schema via the PostTag
type, associated to a Post
entry.
Likewise, a custom post type, defined by any theme or plugin (such as "product"
), can have its own taxonomy tag associated to it (such as "product-cat"
). As these custom post types are not mapped to the GraphQL schema, they are resolved via type GenericCustomPost
, and their tags are resolved as GenericTag
.
We use fields tag
and tags
to fetch tag data, which indicate which taxonomy they refer to via field argument taxonomy
. The result is of the union type TagUnion
, which includes entries from either PostTag
or GenericTag
(depending on the entry's taxonomy).
For instance, this query retrieves tags with taxonomy "product-tag"
:
Allowing access to unmapped tag taxonomies
The tag taxonomies accessible via the GenericTag
type must be explicitly configured in the plugin Settings page, as explained in guide Adding a custom tag taxonomy to the schema.