Closed missionmike closed 1 month ago
I plan to dive into this to learn a bit more about how this works under the hood. If I make progress perhaps I can open a PR to patch.
If anyone could point me to a place in the code that handles this functionality, it could give me a head start.
Thanks to everybody involved for working on these plugins!
Hey @missionmike, I believe that this is related to users not being public by default, until they author a published post. You can read more about that here https://www.wpgraphql.com/docs/users#sensitive-data.
We also have a post about how to make users public https://www.wpgraphql.com/2020/12/11/allowing-wpgraphql-to-show-unpublished-authors-in-user-queries
Hoping this helps! If you believe that this could be a different issue, feel free to add more details below.
@josephfusco wow! I searched all over and didn't stumble across this article. This worked perfectly. Thank you so much.
I tested by adding these hooks to functions.php
in my minimal repro, as stated in the article you shared:
add_filter( 'graphql_connection_query_args', function( $query_args, $connection_resolver ) {
if ( $connection_resolver instanceof \WPGraphQL\Data\Connection\UserConnectionResolver ) {
unset( $query_args['has_published_posts'] );
}
return $query_args;
}, 10, 2 );
add_filter( 'graphql_object_visibility', function( $visibility, $model_name, $data, $owner, $current_user ) {
// only apply our adjustments to the UserObject Model
if ( 'UserObject' === $model_name ) {
$visibility = 'public';
}
return $visibility;
}, 10, 5 );
Results in Postman using "select multiple" on the post that has "admin" as the author, and using two author users in ACF without published posts:
Sorry I didn't find this earlier, but perhaps this issue's SEO will help others who stumble across the same issue in the future.
Thanks so much for getting back to me! Seems like this can be closed so I'll close it out.
Description
When I set a value for a Users ACF field, sometimes the user value is not returned via GraphQL.
Example below showing:
However, the REST response does include the user value:
When I change the post author to "User Two", I can see the expected result in WPGraphQL response (see Post Author value in right side of screenshot):
This issue also affects the ACF Users field when "Select Multiple" is enabled on the field. WPGraphQL will only return one user if it's the post author. Otherwise, the result is empty.
Returns user when user is the same as post author:
Returns empty list when none of users are the post author:
However, REST response will consistently return all ACF Users values:
Steps to reproduce
Use this repository to access a quick minimal reproduction: https://github.com/missionmike/wordpress-minimal-repro-wpgraphql-acf-multiple-users
Steps to reproduce are included in the README, but I will paste the general steps here:
PHP or JSON export of the ACF Field Group(s)
group_66be57e0d401c.json.zip
Additional context
No response
WPGraphQL Version
1.28.0
WPGraphQL For ACF Version
2.4.1
ACF (Advanced Custom Fields) Version. Free or Pro?
6.3.5 Free
WordPress Version
6.6.1
PHP Version
8.2.22
Additional enviornment details
No response
Please confirm that you have searched existing issues in the repo.
Please confirm that you have disabled ALL plugins except for WPGraphQL, WPGraphQL For ACF, ACF, etc.