Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #147 from wp-graphql/release/v0.3.4
Browse files Browse the repository at this point in the history
Release/v0.3.4
  • Loading branch information
jasonbahl authored Jun 18, 2020
2 parents ea3b239 + 8748465 commit 9bb3d7a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ To install the plugin from Github, you can [download the latest release zip file
[Click here](https://wordpress.org/support/article/managing-plugins/) to learn more about installing WordPress plugins from a Zip file.

### Installing from Composer <a name="install-with-composer" />
`@todo`

`composer require wp-graphql/wp-graphql-acf`

## Dependencies <a name="dependencies" />
In order to use WPGraphQL for Advanced Custom Fields, you must have [WPGraphQL](https://github.com/wp-graphql/wp-graphql) and [Advanced Custom Fields](https://advancedcustomfields.com) (free or pro) installed and activated.
Expand All @@ -71,7 +72,7 @@ Whatever method you use to register ACF fields to your WordPress site should wor

The first step in using Advanced Custom Fields with WPGraphQL is to [create an ACF Field Group](https://www.advancedcustomfields.com/resources/creating-a-field-group/).

By default, field groups are _not_ exposed to WPGraphQL. You must opt-in to expose your ACF Field Groups and fields to the WPGraphQL Schema as some information managed my your ACF fields may not be intended for exposure in a queryable API like WPGraphQL.
By default, field groups are _not_ exposed to WPGraphQL. You must opt-in to expose your ACF Field Groups and fields to the WPGraphQL Schema as some information managed by your ACF fields may not be intended for exposure in a queryable API like WPGraphQL.

#### Show in GraphQL Setting

Expand Down
16 changes: 11 additions & 5 deletions src/class-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -729,19 +729,25 @@ protected function register_graphql_field( $type_name, $field_name, $config ) {
$type = $tax_object->graphql_single_name;
}
}

$is_multiple = isset($acf_field['field_type']) && in_array( $acf_field['field_type'], array('checkbox', 'multi_select'));

$field_config = [
'type' => [ 'list_of' => $type ],
'resolve' => function( $root, $args, $context, $info ) use ( $acf_field ) {
'type' => $is_multiple ? ['list_of' => $type ] : $type,
'resolve' => function( $root, $args, $context, $info ) use ( $acf_field, $is_multiple ) {
$value = $this->get_acf_field_value( $root, $acf_field );
$terms = [];
/**
* If this is multiple, the value will most likely always be an array.
* If it isn't, we want to return a single term id.
*/
if ( ! empty( $value ) && is_array( $value ) ) {
foreach ( $value as $term ) {
$terms[] = DataSource::resolve_term_object( (int) $term, $context );
}
return $terms;
} else {
return DataSource::resolve_term_object( (int) $value, $context );
}

return $terms;
},
];
break;
Expand Down
2 changes: 1 addition & 1 deletion wp-graphql-acf.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Author URI: https://www.wpgraphql.com
* Text Domain: wp-graphql-acf
* Domain Path: /languages
* Version: 0.3.3
* Version: 0.3.4
* Requires PHP: 7.0
* GitHub Plugin URI: https://github.com/afragen/github-updater
*
Expand Down

0 comments on commit 9bb3d7a

Please sign in to comment.