WordPress-Daten abfragenBlöcke
Blöcke
Lies mehr in der Anleitung Arbeiten mit (Gutenberg-)Blöcken.
Dies sind Beispiele für queries zum Abrufen von Block-Daten.
Blöcke eines Custom Posts über einen Block-Typ abrufen
Daten für alle Blöcke in einem Post abrufen:
{
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
}
}
}
}
}
}
}
}Nur Blöcke bestimmter Typen abrufen:
{
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
}
}
}
}
}
}
}
}Blöcke ausschließen:
{
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
}
}
}
}
}
}
}
}Block-Daten eines Custom Posts über einen JSONObject-Typ abrufen
Daten für alle Blöcke in einem Post abrufen:
{
posts(by: { id: 19 }) {
blockDataItems
}
}Nur Blöcke bestimmter Typen abrufen:
{
posts(by: { id: 19 }) {
blockDataItems(
filterBy: {
include: [
"core/heading",
"core/paragraph"
]
}
)
}
}Blöcke ausschließen:
{
posts(by: { id: 19 }) {
blockDataItems(
filterBy: {
exclude: [
"core/heading",
"core/paragraph"
]
}
)
}
}Abgeflachte Block-Daten eines Custom Posts abrufen
Das Feld blockFlattenedDataItems flacht die im Custom Post enthaltene Block-Hierarchie auf eine einzige Ebene ab. Dadurch schließt die Filterung nach Blocktyp auch innere Blöcke ein, deren übergeordneter Block ausgeschlossen ist.
Daten für alle Blöcke in einem Post abrufen:
{
posts(by: { id: 19 }) {
blockFlattenedDataItems
}
}Nur Blöcke bestimmter Typen abrufen:
{
posts(by: { id: 19 }) {
blockFlattenedDataItems(
filterBy: {
include: [
"core/heading",
"core/paragraph",
"core/columns",
"core/column"
]
}
)
}
}Next