Home > Blockchain >  Gatsby: Can I query an unpublished media item in the WordPress library using Gatsby graphql?
Gatsby: Can I query an unpublished media item in the WordPress library using Gatsby graphql?

Time:03-11

When I try to query a specific (unpublished) image in the Wordpress media library using GraphQl in Gatsby, no data is returned.

Query (from http://localhost:8000/___graphql) query composer

query MyQuery {
  wpMediaItem(databaseId: {eq: 160}) {
    id
    title
    uri
    slug
    localFile {
      childImageSharp {
        gatsbyImageData(width: 1188, layout: CONSTRAINED, placeholder: BLURRED)
      }
    }
  }
}

Result:

{
  "data": {
    "wpMediaItem": null
  },
  "extensions": {}
}

Any pointers as to where my mistake lies?

CodePudding user response:

Can I query an unpublished media item in the WordPress library using Gatsby graphql?

Short answer: no, you can't. When you unpublish an image it's removed from the data store so it's not queryable. If for some reason it appears is because of cache-related issues.

It's how WordPress image handling works, it's not on Gatsby-side.

More details: https://github.com/gatsbyjs/gatsby/issues/13104

  • Related