Gatsby and WordPress graphQL : query multiple images by id

Considering you are running latest plugin versions


Answer 1

Your query could look something like this:

query ImageQuery {
  allWpMediaItem(filter: {databaseId: {in: [390, 164]}}) {
    nodes {
      localFile {
        childImageSharp {
          gatsbyImageData(layout: CONSTRAINED, formats: [AVIF, WEBP, JPG])
        }
      }
    }
  }
}

Obviously you have to adjust the image options to your needs.


Answer 2

If you actually want to define a set of images to return under a custom query you would need to extend the WPGraphQL schema and return the array of images. The easiest option I can think of is to create a Custom Post Type Slider and add a Repeater field through Advanced Custom Fields. Since ACF is supported with a WPGraphQL Extension it is pretty simple to add it to the schema. You just have to add the Post Type to the schema too. See the docs here: www.wpgraphql.com/docs/custom-post-types/

Read more here: Source link