Display which posts have a thumbnail, and which have not

🔥 This query is already included in Gato GraphQL, as Persisted Query “Fetch posts by thumbnail”.

This query retrieves all posts that have a thumbnail, and those that do not.

query GetPostsWithAndWithoutThumbnail {
postsWithThumbnail: posts(
filter: {
metaQuery: {
key: "_thumbnail_id",
compareBy: {
key: {
operator: EXISTS
}
}
}
},
pagination: { limit: -1 }
) {
id
title
featuredImage {
id
src
}
}

postsWithoutThumbnail: posts(
filter: {
metaQuery: {
key: "_thumbnail_id",
compareBy: {
key: {
operator: NOT_EXISTS
}
}
}
},
pagination: { limit: -1 }
) {
id
title
}
}

Tutorial lessons explaining how the query works permalink