Closed maximilliangeorge closed 1 year ago
Can confirm that. Taxonomy registered on post types post
and page
are working in GraphQL. But not product
.
Only that works:
query NewQuery {
products {
nodes {
name
taxonomy {
nodes {
name
}
}
}
}
}
But not where
.
Have you tried using the taxonomy filter like this? In this example I am querying products by an array of inclusive and exclusive taxonomy objects.
GraphQL Query
query filterPacks(
$Genres: [String]
$GenresExclude: [String]
$Formats: [String]
$FormatsExclude: [String]
$onSale: Boolean
) {
products(
where: {
onSale: $onSale
taxonomyFilter: {
filters: [
{ taxonomy: FORMAT, terms: $Formats, operator: AND }
{ taxonomy: FORMAT, terms: $FormatsExclude, operator: NOT_IN }
{ taxonomy: GENRE, terms: $Genres, operator: AND }
{ taxonomy: GENRE, terms: $GenresExclude, operator: NOT_IN }
]
}
search: $search,
status: "Publish"
}
first: $perPage
before: $before
after: $after
)
}
Here is how the custom taxonomies were registered for WPGraphQL & WooGraphQL
functions.php
add_action('init', function () {
register_taxonomy('product_genre', 'product', [
'labels' => [
'menu_name' => __('Genres', 'your-textdomain'), //@see https://developer.wordpress.org/themes/functionality/internationalization/
],
'show_in_graphql' => true,
'graphql_single_name' => 'genre',
'graphql_plural_name' => 'genres',
]);
register_taxonomy('product_format', 'product', [
'labels' => [
'menu_name' => __('Formats', 'your-textdomain'), //@see https://developer.wordpress.org/themes/functionality/internationalization/
],
'show_in_graphql' => true,
'graphql_single_name' => 'format',
'graphql_plural_name' => 'formats',
]);
});
Yeah, I tried that. But GraphQL simply doesn't know about my taxonomy.
Register
add_action('init', function() {
register_taxonomy('shop', array('post', 'page', 'product'), array(
'labels' => array(
'name' => 'Shops',
'singular_name' => 'Shop',
'search_items' => 'Shops suchen',
'edit_item' => 'Shop bearbeiten',
'update_item' => 'Shop aktualisieren',
'menu_name' => 'Shops',
'add_new_item' => 'Neuen Shop erstellen',
'separate_items_with_commas' => 'Shops durch Komma trennen',
),
'show_admin_column' => true,
'show_in_graphql' => true,
'graphql_single_name' => 'shop',
'graphql_plural_name' => 'shops',
));
});
Query
query NewQuery {
products(
where: {taxonomyFilter: {filters: {taxonomy: SHOP, operator: AND, terms: "shop.domain.tld"}}}
) {
edges {
node {
id
}
}
}
}
Error
{
"errors": [
{
"message": "Field \"products\" argument \"where\" requires type ProductTaxonomyEnum, found SHOP.",
"extensions": {
"category": "graphql"
},
"locations": [
{
"line": 3,
"column": 50
}
]
}
],
"extensions": {
"debug": []
}
}
Never mind. I use the plugin Code Snippets for this experiment and snippet scope needs to be everywhere, not just admin. taxonomyFilter
is working fine, now.
That is an okay-ish workaround for me. Don't know about your use case, @maximilliangeorge.
@maximilliangeorge Have you tried removing the 0
priority.
@maximilliangeorge Closing this due to inactivity.
Describe the bug I can't query posts by custom taxonomy on products, but it works on posts.
To Reproduce Steps to reproduce the behavior:
1) Register custom taxonomies for both products and posts for comparison:
2) Create one or more posts using the Post Models taxonomy. 3) Create one or more products using the Product Models Taxonomy 4) Try querying the products and posts respectively. The product taxonomy does not contain any products.
Expected behavior Products should be exposed under a custom taxonomy for products, just like in posts.
Screenshots N/A
Desktop (please complete the following information):
Smartphone (please complete the following information):
Plugin Versions
Additional context N/A