GCBGutenberg
Control Blocks
Buy

Field type

query-loop

A paginated server-side query over a post type. The block renders page 1 server-side; the front end fetches further pages from the GCB query REST endpoint. Use this for "show all of a CPT, paginated/filterable" — as opposed to relationship, where an editor hand-picks a fixed set.

Type: query-loop · Stored attribute type: object

Stored value

object — the query config (postType, perPage, orderby, order, pagination, filterTaxonomies)

Supports

  • Server-side WP_Query by post type
  • Pagination (numbered pager or load-more button)
  • Front-end taxonomy filtering (AND across facets, OR within a facet)
  • Ordering (date / title / menu_order / rand / modified)

Config options

OptionTypeDefaultDescription
postTypestringThe post type slug to query (usually the CPT the records live in).
perPageinteger12Records per page (1–100, capped at 100).
orderbystringdateOne of: date, title, menu_order, rand, modified.
orderstringDESCASC or DESC.
paginationstringnumberednumbered (page buttons), loadmore (a Load-more button), or none.
enableTaxonomyFilterbooleanfalseShow front-end taxonomy filter controls.
filterTaxonomies{ slug, label }[]Taxonomies the visitor can filter by (must belong to the post type). Only these are honoured by the endpoint.

Gotchas

  • Set attributeType: "object" on the control — the stored value is the query config object.
  • render.php must NOT write its own WP_Query. Call GCBLite\Blocks\Queries\QueryLoop::render_items($config, fn($post) => "...") — it owns the query, the current page, the active filters and the pager markup, so the same template serves page 1 (server) and pages 2+ (the REST fragment).
  • The wrapper needs data-block (the block name) and data-attrs (wp_json_encode of $attributes) so view.js can fetch more pages from /gcblite/v1/query.
  • Unlike relationship, the editor does not pick individual records here — the query decides what shows. Use relationship when the client wants to curate an exact, ordered set.

Example

JSON
{ "id": "ctrl_query",
  "type": "query-loop",
  "label": "People",
  "attributeKey": "query",
  "attributeType": "object",
  "postType": "team-member",
  "perPage": 12,
  "orderby": "title",
  "order": "ASC",
  "pagination": "numbered",
  "enableTaxonomyFilter": true,
  "filterTaxonomies": [ { "slug": "department", "label": "Department" } ] }

Every field also takes the keys common to all fields.

Built from GCB Lite 0.4.0 (ce232d4). Source: schemas/controls/query-loop.md.

Copyright © 2026 Runchain. WordPress is a trademark of the WordPress Foundation.