Description
Hi!
My app needs to fetch media by slug on the add_attachment WP's hook.
When a media is uploaded in the library, graphql returns the media object.
But when the media is uploaded through the post editor (like for a featured image), graphql returns null.
Steps to reproduce
- Start to add a new post
- Click on "set featured image"
- Upload a new image
At this point, don't touch anything else, keep the editor open and the post as draft.
- Try to get the new media by its slug,
null will be responded
- Try to get the same new media by its database id, you'll get the media object
As the media has been uploaded, its slug and database id can be found by editing it in the library.
Additional context
Here's an example of a query:
query NewQuery {
mediaById: mediaItem(id: "7815", idType: DATABASE_ID) {
id
databaseId
slug
status
}
mediaBySlug: mediaItem(id: "3-2", idType: SLUG) {
id
databaseId
slug
}
}
And its response:
{
"data": {
"mediaById": {
"id": "cG9zdDo3ODE1",
"databaseId": 7815,
"slug": "3-2",
"status": "inherit"
},
"mediaBySlug": null
},
"extensions": {
"debug": [],
"queryAnalyzer": {
"keys": "dee80d77ad26698c63b98a4b7eea631db104668cd4552723d5c2d666f2ca1150 graphql:Query operation:NewQuery cG9zdDo3ODE1",
"keysLength": 110,
"keysCount": 4,
"skippedKeys": "",
"skippedKeysSize": 0,
"skippedKeysCount": 0,
"skippedTypes": []
}
}
}
I understand that the media status is draft (inherited from the parent, the post still on draft). But if the query by database id can return the object, why can't the query by slug?
Please note that the requested object (id 7815) has the right requested slug (3-2).
This issue #1999 looks like having some similarities, but the use case is different. I'm trying to directly fetch the media, not the featuredImage through the post.
WPGraphQL Version
2.5.1
WordPress Version
6.8.3
PHP Version
8.4.14
Additional environment details
No WGraphQL extensions installed.
Also tried on PHP 8.3.15.
Please confirm that you have searched existing issues in the repo.
Please confirm that you have disabled ALL plugins except for WPGraphQL.
Description
Hi!
My app needs to fetch media by slug on the
add_attachmentWP's hook.When a media is uploaded in the library, graphql returns the media object.
But when the media is uploaded through the post editor (like for a featured image), graphql returns
null.Steps to reproduce
At this point, don't touch anything else, keep the editor open and the post as draft.
nullwill be respondedAs the media has been uploaded, its slug and database id can be found by editing it in the library.
Additional context
Here's an example of a query:
And its response:
I understand that the media status is draft (inherited from the parent, the post still on draft). But if the query by database id can return the object, why can't the query by slug?
Please note that the requested object (id
7815) has the right requested slug (3-2).This issue #1999 looks like having some similarities, but the use case is different. I'm trying to directly fetch the media, not the featuredImage through the post.
WPGraphQL Version
2.5.1
WordPress Version
6.8.3
PHP Version
8.4.14
Additional environment details
No WGraphQL extensions installed.
Also tried on PHP 8.3.15.
Please confirm that you have searched existing issues in the repo.
Please confirm that you have disabled ALL plugins except for WPGraphQL.