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

Commit 164f2b3

Browse files
authored
Merge pull request #301 from rsm0128/bug/#300-relationship-error-post-deleted
Fix: Internal server error 500 for relationship to non-published post
2 parents 4d62d71 + 61b16a6 commit 164f2b3

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/class-config.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -689,12 +689,14 @@ protected function register_graphql_field( string $type_name, string $field_name
689689
$post_object = get_post( $post_id );
690690
if ( $post_object instanceof \WP_Post ) {
691691
$post_model = new Post( $post_object );
692-
$relationship[] = $post_model;
692+
if ( 'private' != $post_model->get_visibility() ) {
693+
$relationship[] = $post_model;
694+
}
693695
}
694696
}
695697
}
696698

697-
return isset( $value ) ? $relationship : null;
699+
return empty( $relationship ) ? null : $relationship;
698700

699701
},
700702
];

tests/wpunit/ExplicitOptionsTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public function testExplicitOptions() {
8989
'show_in_graphql' => true,
9090
'graphql_single_name' => 'acfCpt',
9191
'graphql_plural_name' => 'acfCpts',
92+
'public' => true,
9293
]
9394
);
9495

@@ -148,7 +149,7 @@ public function testExplicitOptions() {
148149
]
149150
);
150151

151-
$expected_text_3 = 'test value2';
152+
$expected_text_3 = 'test value3';
152153
update_field( 'acf_text_field', $expected_text_3, $cpt_id );
153154

154155
// post assert validation.

tests/wpunit/PostObjectFieldsTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1213,8 +1213,8 @@ public function testQueryMultipleSelectFieldWithNoValueSet() {
12131213
public function testQueryFieldOnCustomPostType() {
12141214

12151215
register_post_type( 'acf_test', [
1216-
'show_ui' => true,
1217-
'show_in_graphql' => 'true',
1216+
'public' => true,
1217+
'show_in_graphql' => 'true',
12181218
'graphql_single_name' => 'acfTest',
12191219
'graphql_plural_name' => 'acfTests'
12201220
] );

0 commit comments

Comments
 (0)