New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to retrieve products by custom taxonomy #606
Comments
Can confirm that. Taxonomy registered on post types Only that works: query NewQuery {
products {
nodes {
name
taxonomy {
nodes {
name
}
}
}
}
} But not |
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. 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 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. That is an okay-ish workaround for me. Don't know about your use case, @maximilliangeorge. |
@maximilliangeorge Have you tried removing the |
@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:
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
The text was updated successfully, but these errors were encountered: