WordPress verilerini sorgula
WordPress verilerini sorgulaBloklar

Bloklar

Gutenberg blokları ile çalışma rehberinde daha fazlasını okuyun.

Bunlar blok verilerini almak için queries örnekleridir.

Özel bir gönderideki blokları Block türü aracılığıyla alma

Bir gönderideki tüm blokların verilerini alma:

{
  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
              }
            }
          }
        }
      }
    }
  }
}

Yalnızca belirli türdeki blokları alma:

{
  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
              }
            }
          }
        }
      }
    }
  }
}

Blokları hariç tutma:

{
  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
              }
            }
          }
        }
      }
    }
  }
}

Özel bir gönderideki blok verilerini JSONObject türü aracılığıyla alma

Bir gönderideki tüm blokların verilerini alma:

{
  posts(by: { id: 19 }) {
    blockDataItems
  }
}

Yalnızca belirli türdeki blokları alma:

{
  posts(by: { id: 19 }) {
    blockDataItems(
      filterBy: {
        include: [
          "core/heading",
          "core/paragraph"
        ]
      }
    )
  }
}

Blokları hariç tutma:

{
  posts(by: { id: 19 }) {
    blockDataItems(
      filterBy: {
        exclude: [
          "core/heading",
          "core/paragraph"
        ]
      }
    )
  }
}

Özel bir gönderideki düzleştirilmiş blok verilerini alma

blockFlattenedDataItems alanı, özel gönderide yer alan blok hiyerarşisini tek bir düzeye düzleştirir. Böylece blok türüne göre filtreleme yapıldığında, üst bloğu hariç tutulan iç bloklar da sonuçlara dahil edilir.

Bir gönderideki tüm blokların verilerini alma:

{
  posts(by: { id: 19 }) {
    blockFlattenedDataItems
  }
}

Yalnızca belirli türdeki blokları alma:

{
  posts(by: { id: 19 }) {
    blockFlattenedDataItems(
      filterBy: {
        include: [
          "core/heading",
          "core/paragraph",
          "core/columns",
          "core/column"
        ]
      }
    )
  }
}