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

Fix: Internal server error 500 for relationship to non-published post #301

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/class-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -689,12 +689,14 @@ protected function register_graphql_field( string $type_name, string $field_name
$post_object = get_post( $post_id );
if ( $post_object instanceof \WP_Post ) {
$post_model = new Post( $post_object );
$relationship[] = $post_model;
if ( 'private' != $post_model->get_visibility() ) {
$relationship[] = $post_model;
}
}
}
}

return isset( $value ) ? $relationship : null;
return empty( $relationship ) ? null : $relationship;

},
];
Expand Down
3 changes: 2 additions & 1 deletion tests/wpunit/ExplicitOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public function testExplicitOptions() {
'show_in_graphql' => true,
'graphql_single_name' => 'acfCpt',
'graphql_plural_name' => 'acfCpts',
'public' => true,
]
);

Expand Down Expand Up @@ -148,7 +149,7 @@ public function testExplicitOptions() {
]
);

$expected_text_3 = 'test value2';
$expected_text_3 = 'test value3';
update_field( 'acf_text_field', $expected_text_3, $cpt_id );

// post assert validation.
Expand Down
4 changes: 2 additions & 2 deletions tests/wpunit/PostObjectFieldsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1213,8 +1213,8 @@ public function testQueryMultipleSelectFieldWithNoValueSet() {
public function testQueryFieldOnCustomPostType() {

register_post_type( 'acf_test', [
'show_ui' => true,
'show_in_graphql' => 'true',
'public' => true,
'show_in_graphql' => 'true',
'graphql_single_name' => 'acfTest',
'graphql_plural_name' => 'acfTests'
] );
Expand Down