From 22e964a963698dc19b8950626f1bcb8d306f3bc6 Mon Sep 17 00:00:00 2001 From: Jacob Arriola Date: Wed, 21 Oct 2020 20:50:44 -0700 Subject: [PATCH] Filter: allow non-core post types in Relationship Without this filter, non-core types (ie WooCommerce) cannot declare their proper Type source. This filter is inline with the `graphql_acf_post_object_source` filter on line 617. --- src/class-config.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/class-config.php b/src/class-config.php index 773b7f1..bee36b0 100644 --- a/src/class-config.php +++ b/src/class-config.php @@ -516,8 +516,17 @@ protected function register_graphql_field( $type_name, $field_name, $config ) { foreach ( $value as $post_id ) { $post_object = get_post( $post_id ); if ( $post_object instanceof \WP_Post ) { - $post_model = new Post( $post_object ); - $relationship[] = $post_model; + $post_model = new Post( $post_object ); + + /** + * Allow for filtering of the post model. In case a non-core defined post-type is being targeted. + * + * @param mixed|null $post_model GraphQL Model + * @param mixed|null $post_object Root ACF Field value. + * @param AppContext $context AppContext instance. + * @param ResolveInfo $info ResolveInfo instance. + */ + $relationship[] = apply_filters( 'graphql_acf_relationship_model', $post_model, $post_object, $context, $info ); } } }