Closed drewbaker closed 5 years ago
@drewbaker I just tried and this seems to work for me:
{
pages(
where: {
taxQuery: {
taxArray: [
{
taxonomy: CUSTOMTERM,
terms: ["New Term"],
field: NAME
}
]
}
}
) {
nodes {
id
link
slug
}
}
}
Here's the steps I took:
Register Custom Taxonomy connected to Pages:
add_action( 'init', function() {
register_taxonomy(
'custom_tax',
'page',
array(
'public' => true,
'hierarchical' => false,
'labels' => array(
'name' => _x( 'Custom', 'post format' ),
'singular_name' => _x( 'Custom', 'post format' ),
),
'query_var' => true,
'show_ui' => true,
'_builtin' => true,
'show_in_rest' => true,
'show_in_graphql' => true,
'graphql_single_name' => 'CustomTerm',
'graphql_plural_name' => 'CustomTerms'
)
);
} );
Assign a page to "New Term" in that taxonomy
Test the query:
Weird, this is totally not working for me.
Do you see anything I am missing?
For future people: So I spoke with Jason today and found a little hidden setting, by default all page queries have parent: 0
set on them, so if you want any depth page, then you need to set parent: null
in the where clause! This ended up working!
{
pages(
where: {
parent: null,
taxQuery: {
taxArray: [
{
taxonomy: TYPE,
terms: ["colour"],
field: NAME
}
]
}
}
) {
nodes {
id
link
slug
}
}
}
I have a custom taxonomy called
type
. It is used onpages
.The below
taxQuery
doesn't work, it returns empty results. There are 11 pages in thetype
category with sluglatest
.And the results are: