Expose media_tag and other taxonomies to wpgraphql
-
It looks like the taxonomies created with TaxoPress aren’t exposed in wpgraphql under the regular taxonomies:
query Taxonomy {
taxonomies {
nodes {
description
id
name
label
public
}
}
}
// returns the following when TaxoPress is enabled:
{
"data": {
"taxonomies": {
"nodes": [
{
"description": "",
"id": "dGF4b25vbXk6Y2F0ZWdvcnk=",
"name": "category",
"label": null,
"public": null
},
{
"description": "",
"id": "dGF4b25vbXk6cG9zdF90YWc=",
"name": "post_tag",
"label": null,
"public": null
},
{
"description": "",
"id": "dGF4b25vbXk6cG9zdF9mb3JtYXQ=",
"name": "post_format",
"label": null,
"public": null
}
]
}
},
}However you can expose the taxonomy by registering it to show in GraphQL. This may be good to add to the plugin documentation for others:
function register_media_tag_graphql()
{
register_taxonomy('media_tag', 'attachment', array(
'show_in_graphql' => true,
'graphql_single_name' => 'MediaTag',
'graphql_plural_name' => 'MediaTags',
));
}
add_action('init', 'register_media_tag_graphql');Now I can query the tags from the taxoPress taxonomy:
query MediaTags {
mediaTags {
nodes {
databaseId
name
slug
taxonomyName
}
}
}
// returns:
{
"data": {
"mediaTags": {
"nodes": [
{
"databaseId": 7,
"name": "los angeles",
"slug": "los-angeles",
"taxonomyName": "media_tag"
},
{
"databaseId": 6,
"name": "toronto",
"slug": "toronto",
"taxonomyName": "media_tag"
}
]
}
},
}
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- You must be logged in to reply to this topic.