wp-graphql / wp-graphql/wp-graphql
User connections `hasPublishedPosts` should not allow `ATTACHMENT` value
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 3.8k
- Forks
- 472
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 85
Description
Description
The UserConnectionWhereArgs.hasPublishedPosts is currently of type ContentTypeEnum, which offers ATTACHMENT as a possible value.
However, the underling has_published_posts query arg does not support filtering by attachment.
$query = new \WP_User_Query( [
'has_published_posts' => 'attachment'
] );
error_log( print_r( $query->get_results() ) ); // will always return an empty array.
This is confirmed in our test suite (part of #2996) as well.
As a quick "fix", I recommend adding a graphql_debug() message alerting users to the bug.
Long term, I suggest we deprecate hasPublishedPosts in favor of something like hasPublishedContent, which uses an enum type that doesnt include attachments.
Steps to reproduce
- Create an attachment for a specific user and post:
$attachment_id = wp_insert_attachment(
[
'post_author' => $user_id,
'post_type' => 'attachment',
'post_status' => 'inherit',
'post_title' => 'Test attachment for PostTypeQueryForMedia',
'post_parent' => $post_id,
]
);
- Query for users with
hasPublishedPosts: ATTACHMENT:
query {
users ( where: { hasPublishedPosts: ATTACHMENT } ) {
nodes {
databaseId
}
}
}
- Confirm no users are returned.
Additional context
I didnt create a PR to deprecate hasPublishedPosts and create hasPublishedContent because I'm thinking that a "sans-attachment" enum is likely necessary/useful in other parts of the codebase 🤔
WPGraphQL Version
1.16.0
WordPress Version
6.3.1
PHP Version
8.1.15
Additional environment details
No response
Please confirm that you have searched existing issues in the repo.
- Yes
Please confirm that you have disabled ALL plugins except for WPGraphQL.
- Yes
- My issue is with compatibility with a specific WordPress plugin, and I have listed all my installed plugins (and version info) above.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with tests/wpunit/UserConnectionQueriesTest.php, especially the linked has_published_posts coverage, and trace UserConnectionWhereArgs.hasPublishedPosts to the underlying WP_User_Query argument. Review how the enum is defined and how schema deprecations or debug messages are handled. Done means the unsupported ATTACHMENT case is no longer silently exposed, with tests covering the chosen compatibility behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, php
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100