Skip to content

Commit 190aea3

Browse files
committed
- ensure we're dealing with an array before mapping over it
1 parent ccf51d2 commit 190aea3

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/FieldType/Taxonomy.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
class Taxonomy {
1010

1111
/**
12+
* Register support for the "taxonomy" ACF field type
1213
*/
1314
public static function register_field_type(): void {
1415
register_graphql_acf_field_type(
@@ -25,22 +26,29 @@ public static function register_field_type(): void {
2526
return null;
2627
}
2728

29+
$values = [];
2830
if ( ! is_array( $value ) ) {
29-
$value[] = $value;
31+
$values[] = $value;
32+
} else {
33+
$values = $value;
3034
}
3135

32-
$value = array_map(
36+
$ids = array_map(
3337
static function ( $id ) {
3438
return absint( $id );
3539
},
36-
$value
40+
$values
3741
);
3842

43+
if ( empty( $ids ) ) {
44+
return null;
45+
}
46+
3947
$resolver = new TermObjectConnectionResolver( $root, $args, $context, $info );
4048
return $resolver
4149
// Set the query to include only the IDs passed in from the field
4250
// and orderby the ids
43-
->set_query_arg( 'include', $value )
51+
->set_query_arg( 'include', $ids )
4452
->set_query_arg( 'orderby', 'include' )
4553
->get_connection();
4654
},

0 commit comments

Comments
 (0)