You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.
I’m trying to relate products from within a Flexible Content field in ACF. That works when querying a single product with ACF Post Object by setting “Select multiple values?” to No.
However, when querying for multiple values, instead of an array of product objects, I get null in WPGraphiQL.
Same happens if using ACF Relationship Field, which I think always returns an array. The result is the same for simple and variable products.
This should be easy to replicate as it happens to me however I define my field groups
Using
WPGraphQL 0.10.2
wp-graphql-woocommerce 0.5.1
wp-graphql-acf 0.3.4
The text was updated successfully, but these errors were encountered:
@HumidBrains@jasonbahl
I discovered the same problem in our project, and it seems like its the graphql_acf_post_object_source filter that wp-graphql-woocommerce uses and returns wrong value.
File includes/class-acf-schema-filters.php line 56.
public static function resolve_post_object_source( $source, $value ) {
$post = get_post( $value );
if ( $post instanceof \WP_Post ) {
switch ( $post->post_type ) {
case 'shop_coupon':
$source = new Coupon( $post->ID );
break;
case 'shop_order':
$source = new Order( $post->ID );
break;
case 'product':
$source = new Product( $post->ID );
break;
}
}
return $source;
}
Since the Post Object field can return both null and an array this code wont work because when querying a single product get_post returns itself, and the code has no support for an array.
This is a pretty old issue, but it typically occurred when there were orphaned IDs stored as values for ACF Fields.
WPGraphQL for ACF has been re-built over here: https://github.com/wp-graphql/wpgraphql-acf and relational fields are all now using connections and WPGraphQL DataLoaders which account for issues like orphaned IDs not throwing errors.
I recommend switching to the new version of WPGraphQL for ACF at your earliest convenience as it's the version we'll be releasing on WordPress.org and supporting long-term.
I’m trying to relate products from within a Flexible Content field in ACF. That works when querying a single product with ACF Post Object by setting “Select multiple values?” to No.
However, when querying for multiple values, instead of an array of product objects, I get null in WPGraphiQL.
Same happens if using ACF Relationship Field, which I think always returns an array. The result is the same for simple and variable products.
This should be easy to replicate as it happens to me however I define my field groups
Using
WPGraphQL 0.10.2
wp-graphql-woocommerce 0.5.1
wp-graphql-acf 0.3.4
The text was updated successfully, but these errors were encountered: