These are examples of queries to fetch block data.
Fetching data for all blocks in a post:
{
post ( by : { id : 19 }) {
blocks {
... BlockData
}
}
}
fragment BlockData on Block {
name
attributes
# innerHTML
contentSource
innerBlocks {
name
attributes
# innerHTML
contentSource
innerBlocks {
name
attributes
# innerHTML
contentSource
innerBlocks {
name
attributes
# innerHTML
contentSource
innerBlocks {
name
attributes
# innerHTML
contentSource
innerBlocks {
name
attributes
# innerHTML
contentSource
innerBlocks {
name
attributes
# innerHTML
contentSource
innerBlocks {
name
attributes
# innerHTML
contentSource
}
}
}
}
}
}
}
}
Copy
Retrieving only blocks of certain types:
{
post ( by : { id : 19 }) {
blocks (
filterBy : {
include : [
"core/heading" ,
"core/paragraph"
]
}
) {
... BlockData
}
}
}
fragment BlockData on Block {
name
attributes
# innerHTML
contentSource
innerBlocks {
name
attributes
# innerHTML
contentSource
innerBlocks {
name
attributes
# innerHTML
contentSource
innerBlocks {
name
attributes
# innerHTML
contentSource
innerBlocks {
name
attributes
# innerHTML
contentSource
innerBlocks {
name
attributes
# innerHTML
contentSource
innerBlocks {
name
attributes
# innerHTML
contentSource
innerBlocks {
name
attributes
# innerHTML
contentSource
}
}
}
}
}
}
}
}
Copy
Excluding blocks:
{
post ( by : { id : 19 }) {
blocks (
filterBy : {
exclude : [
"core/heading" ,
"core/paragraph"
]
}
) {
... BlockData
}
}
}
fragment BlockData on Block {
name
attributes
# innerHTML
contentSource
innerBlocks {
name
attributes
# innerHTML
contentSource
innerBlocks {
name
attributes
# innerHTML
contentSource
innerBlocks {
name
attributes
# innerHTML
contentSource
innerBlocks {
name
attributes
# innerHTML
contentSource
innerBlocks {
name
attributes
# innerHTML
contentSource
innerBlocks {
name
attributes
# innerHTML
contentSource
innerBlocks {
name
attributes
# innerHTML
contentSource
}
}
}
}
}
}
}
}
Copy
Fetching data for all blocks in a post:
{
posts ( by : { id : 19 }) {
blockDataItems
}
}
Copy
Retrieving only blocks of certain types:
{
posts ( by : { id : 19 }) {
blockDataItems (
filterBy : {
include : [
"core/heading" ,
"core/paragraph"
]
}
)
}
}
Copy
Excluding blocks:
{
posts ( by : { id : 19 }) {
blockDataItems (
filterBy : {
exclude : [
"core/heading" ,
"core/paragraph"
]
}
)
}
}
Copy
Field blockFlattenedDataItems
flattens the block hierarchy contained in the custom post to a single level. Then, filtering by block type will also include inner blocks who have a parent block that is excluded.
Fetching data for all blocks in a post:
{
posts ( by : { id : 19 }) {
blockFlattenedDataItems
}
}
Copy
Retrieving only blocks of certain types:
{
posts ( by : { id : 19 }) {
blockFlattenedDataItems (
filterBy : {
include : [
"core/heading" ,
"core/paragraph" ,
"core/columns" ,
"core/column"
]
}
)
}
}
Copy