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

Commit b2b1aad

Browse files
authored
Merge pull request #146 from seagyn/patch-1
Add support for select & radio in Taxonomy fields
2 parents 019bc91 + a19bd33 commit b2b1aad

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/class-config.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -729,19 +729,25 @@ protected function register_graphql_field( $type_name, $field_name, $config ) {
729729
$type = $tax_object->graphql_single_name;
730730
}
731731
}
732+
733+
$is_multiple = isset($acf_field['field_type']) && in_array( $acf_field['field_type'], array('checkbox', 'multi_select'));
732734

733735
$field_config = [
734-
'type' => [ 'list_of' => $type ],
735-
'resolve' => function( $root, $args, $context, $info ) use ( $acf_field ) {
736+
'type' => $is_multiple ? ['list_of' => $type ] : $type,
737+
'resolve' => function( $root, $args, $context, $info ) use ( $acf_field, $is_multiple ) {
736738
$value = $this->get_acf_field_value( $root, $acf_field );
737-
$terms = [];
739+
/**
740+
* If this is multiple, the value will most likely always be an array.
741+
* If it isn't, we want to return a single term id.
742+
*/
738743
if ( ! empty( $value ) && is_array( $value ) ) {
739744
foreach ( $value as $term ) {
740745
$terms[] = DataSource::resolve_term_object( (int) $term, $context );
741746
}
747+
return $terms;
748+
} else {
749+
return DataSource::resolve_term_object( (int) $value, $context );
742750
}
743-
744-
return $terms;
745751
},
746752
];
747753
break;

0 commit comments

Comments
 (0)