Repository navigation
Blocks Query
Block name: designsetgo/query
Added in: 2.1.0
Category: DesignSetGo
Block family: Query (parent) · Query Results · Query Pagination · Query Filter · Query Group Header · No Results
The Dynamic Query block is the container block for the query family. It owns all query configuration — source, filters, ordering, and pagination — and exposes those settings to its child and sibling blocks via block context. Actual item rendering is handled by the Query Results child block (or by a Slider / Scroll Slides host that takes over rendering).
The block is fully server-rendered: PHP builds the item list once and passes the pre-rendered HTML to the child host block, while sibling blocks (filters, pagination, no-results) read from a per-request state registry so the query runs exactly once per page load.
Key Features:
- Six query sources: Posts, Users, Terms, Manual picks, Current archive, Relationship
- Taxonomy, meta, date, search, author, and offset filtering
- Multi-level AND/OR taxonomy and meta clause groups
- Group-by partitioning (taxonomy / meta / date precision)
- Nested loop support via
designsetgo/parentItemcontext - Live editor preview with an editable first item and server-rendered read-only items
- Template picker on first insert (8 pre-built starting points)
- Template export and import via Inspector buttons
- Style bindings (
dsgoStyleBinding) for dynamic inline CSS - ItemList schema.org markup for Posts queries
- Interactivity API: filter state syncs to URL parameters
- Query Monitor debug panel when QM is active
| Attribute | Type | Default | Notes |
|---|---|---|---|
queryId |
string | "" |
Auto-generated unique ID; used to coordinate with sibling blocks |
source |
string | "posts" |
posts | users | terms | manual | current | relationship
|
postType |
string | "post" |
Post type slug; applies only when source is "posts"
|
perPage |
number | 6 |
Items per page (1–48) |
offset |
number | 0 |
Skip this many items from the start of the result set |
orderBy |
string | "date" |
date | title | menu_order | rand | comment_count | meta_value | meta_value_num
|
orderByMetaKey |
string | "" |
Meta key used when orderBy is meta_value or meta_value_num
|
order |
string | "DESC" |
ASC | DESC
|
search |
string | "" |
Static keyword search (same as s in WP_Query) |
bindSearchTo |
string | "" |
URL parameter name whose value overrides search at render time |
author |
array | [] |
Array of author IDs |
excludeCurrent |
boolean | false |
Exclude the post currently being viewed |
ignoreSticky |
boolean | true |
Ignore sticky post elevation |
manualIds |
array | [] |
Post IDs for source: "manual" (comma-separated in the Inspector, stored as integers) |
taxQuery |
object | {relation:"AND",clauses:[]} |
Taxonomy filter; clauses can be nested groups |
metaQuery |
object | {relation:"AND",clauses:[]} |
Meta filter; clauses can be nested groups |
dateQuery |
object | {relation:"AND",clauses:[]} |
Date filter clauses |
relationshipField |
string | "" |
Meta key or ACF field on the parent post holding related IDs; used with source: "relationship"
|
relationshipFallback |
string | "empty" |
empty | all | parent — what to render when no related items exist |
emitSchema |
boolean | true |
Emit ItemList schema.org JSON-LD for Posts queries |
showPlaceholder |
boolean | true |
Show the template picker when no inner blocks exist |
Source selects what the query iterates:
| Value | What it does |
|---|---|
posts |
Standard WP_Query over any post type; exposes full taxonomy / meta / date filtering |
users |
Iterates WP_User_Query results; skips taxonomy/meta filter panels |
terms |
Iterates taxonomy terms; skips taxonomy/meta filter panels |
manual |
Renders a hand-picked list of post IDs; use the Manual IDs field |
current |
Inherits the current archive's query (useful inside a template part) |
relationship |
Reads a relationship field on the parent post and iterates the referenced posts via post__in
|
Post type — visible only when source is posts. Lists all viewable registered post types.
Relationship field and When no related items — visible only when source is relationship. The field accepts a meta key or ACF field name that holds one or more post IDs (supports arrays, serialized arrays, comma-separated strings, or plain integers). The fallback controls what happens when that field is empty: render nothing (empty), fall back to all posts (all), or render the parent item itself (parent).
Items per page — range control, 1–48.
Offset — number input; shifts the query start position without affecting pagination total.
Order by and Order direction — standard WP_Query orderby and order.
Template I/O — Export and Import buttons for saving and restoring the full block tree as a JSON file. Export downloads query-template-<id>.json; Import calls POST /designsetgo/v1/query/template, validates the payload against the block type registry, generates a fresh queryId, and replaces the current block.
Displayed only when source is posts. Allows any number of taxonomy clauses, each with:
- Taxonomy dropdown (only taxonomies registered for the selected post type)
-
Terms token field (type term names to add; backed by
getEntityRecords) -
Operator —
IN,NOT IN, orAND(require all terms) - Include child terms toggle (default on)
Multiple clauses share a top-level Relation (AND / OR). Clauses can themselves be nested groups at any depth, forming a multi-level AND/OR structure that maps to WP_Query's tax_query.
Displayed only when source is posts. Clause fields:
- Key — meta key name
-
Compare — one of
=,!=,>,>=,<,<=,LIKE,NOT LIKE,IN,NOT IN,EXISTS,NOT EXISTS -
Type —
Text,Numeric, orDate -
Value — hidden for
EXISTS/NOT EXISTS
Multiple clauses share a Relation (AND / OR) and can be nested into groups.
Displayed only when source is posts. Each clause has:
-
Column —
post_date,post_modified,post_date_gmt, orpost_modified_gmt -
Mode —
After,Before, orBetween -
After / Before date fields — accept ISO dates (
YYYY-MM-DD) or PHP relative expressions (-30 days,today,first day of last month)
- Search text — static keyword filter
-
Bind search to URL param — when set, the named URL parameter overrides the static search at render time (e.g. entering
qhere makes?q=keywordfunctional) - Exclude current post — automatically excludes the viewed post from results
- Ignore sticky posts — on by default
-
Manual post IDs — visible only when
sourceismanual; comma-separated list of post IDs
Standard WordPress WP_Query. Supports all filtering controls. Schema.org ItemList markup is emitted when emitSchema is true.
Iterates WP_User_Query results. Bindings in the item template receive the user ID via designsetgo/currentItemId and designsetgo/currentItemType: "user". Taxonomy and meta filter panels are hidden.
Iterates taxonomy terms. Bindings receive the term ID via designsetgo/currentItemId and designsetgo/currentItemType: "term". Taxonomy and meta filter panels are hidden.
Renders a fixed list of post IDs entered in the Inspector. Items appear in the order entered. Useful for curated spotlight sections.
Inherits the current archive query from WordPress. Intended for use inside Full Site Editing archive templates where a WP_Query is already in context.
Reads a relationship field — a meta key or ACF field — on the parent item (determined by block context: the post being edited, or the outer query's current item in a nested loop). The field value can be stored as an array of integers, a serialized PHP array, a comma-separated string, or a plain integer. The block normalizes all these formats, then fetches the referenced posts via post__in.
Configure the Relationship field and the When no related items fallback in the Settings panel.
When groupBy is set on the Query Results child block, items are partitioned into labelled sections before rendering. Each group emits a <section class="dsgo-query-group"> wrapper. The Query Group Header block, when present in the item template, renders once per group with designsetgo/groupLabel and designsetgo/groupValue context filled in.
Three grouping fields are available (configured on Query Results):
| Field |
key values |
Description |
|---|---|---|
taxonomy |
Taxonomy slug | Groups by term; multi-term posts appear in all matching groups |
meta |
Meta key name | Groups by meta value string |
date |
Y, Y-M, or Y-M-D
|
Groups by year, year + month, or full date |
A Query block inside another Query block automatically inherits the outer loop's current item. The outer item is available inside the inner query as:
- Block context key:
designsetgo/parentItem(an object withpostIdandpostType) - PHP global during render:
$GLOBALS['designsetgo_parent_stack']— an ordered array of{postId, postType}objects, one per nesting level
This enables patterns like "for each author, show their latest posts" or "for each product category, show related products" within a single page.
After inserting a template, the editor shows a live preview of query results:
-
Posts source: uses
useEntityRecordsfrom@wordpress/core-datafor instant in-editor data -
Users / Terms sources: fetches from
/designsetgo/v1/query/previewREST endpoint -
Item 0: editable
InnerBlocks— the template the author designs - Items 1..N: server-rendered read-only HTML via the same PHP pipeline as the frontend, ensuring pixel-accurate parity
A result-count badge ("N items") appears in the block header when the query is valid.
On first insert (before any inner blocks exist), the block shows a template picker with 8 starting points:
| Template | Description |
|---|---|
| Minimal | Bare skeleton: Results, No Results, Pagination |
| Blog index | Magazine cards with search + sort + numbered pagination |
| Team directory | Circular avatars in a centered grid |
| Testimonials | Pull-quote cards with load-more |
| Portfolio | Image tiles with category filter and load-more |
| Related posts | Compact horizontal rows; excludes current post |
| Featured carousel | Posts rendered inside a Slider block |
| Post spotlight | Posts rendered inside Scroll Slides |
The dsgoStyleBinding attribute maps CSS property names to a binding source and key. Values are injected as inline styles on the block root at render time.
Security: values containing url(, expression(, javascript:, data:, or the characters ;, {, } are rejected before injection.
Filter interactions and load-more pagination are powered by the WordPress Interactivity API (@wordpress/interactivity). Filter state is reflected in URL parameters so results are shareable and navigable:
| Parameter | Used by |
|---|---|
q |
Search filter |
sort |
Sort filter |
filter_<taxonomy> |
Checkbox and select taxonomy filters |
When JavaScript is unavailable, filter controls fall back to standard <form method="get"> submission for a full-page reload with the same parameters.
When emitSchema is true (the default) and source is "posts", the block emits a JSON-LD ItemList schema.org block in the page <head>. Each list item carries its position and permalink. Disable by setting emitSchema to false in the Inspector's Advanced panel.
A dashboard page at Settings → DesignSetGo → Dynamic Query provides controls for rebuilding the filter index and managing registered filters.
WP-CLI commands:
wp dsgo query index rebuild # Rebuild the full filter index
wp dsgo query index rebuild-filter # Rebuild index for a single filter
wp dsgo query index status # Show current index status
wp dsgo query index drop # Drop the filter index table
When the Query Monitor plugin is active, a "DSGo (N)" panel appears in the QM output showing per-render query args, found-posts count, execution duration, and the SQL statement for each Dynamic Query on the page.
designsetgo_query_args
Fires before every WP_Query run. Use this to modify query arguments globally.
add_filter( 'designsetgo_query_args', function( $args, $atts, $context ) {
// e.g. exclude a specific post type
return $args;
}, 10, 3 );designsetgo/query/{queryId}/args
Same as above but fires only for the query with the matching queryId. Useful for targeting a specific query block without affecting others.
add_filter( 'designsetgo/query/my-query-id/args', function( $args, $atts, $context ) {
return $args;
}, 10, 3 );designsetgo_query_registered_filters
Filter the list of registered filter definitions used by the filter index and count queries.
designsetgo_query_url_params
Extend the URL parameters that the Interactivity API store reads and syncs. By default the allowed list is ['q', 'sort'] plus any key prefixed with filter_.
add_filter( 'designsetgo_query_url_params', function( $params ) {
$params[] = 'my_custom_param';
return $params;
} );designsetgo_query_partition_items( array $post_ids, array $group_spec ): array
Partitions an ordered list of post IDs into labelled groups. $group_spec is an array with keys field (taxonomy, meta, or date) and key (taxonomy slug, meta key, or date precision Y/Y-M/Y-M-D). Returns an array of groups, each with label, value, and ids keys.
$GLOBALS['designsetgo_parent_stack']
An ordered array of item context objects {postId, postType} representing the nesting chain of currently-rendering query items. Index 0 is the outermost loop's current item. Available during any render_block hook or block render callback fired inside a query item.
- The outer wrapper carries
aria-live="polite"and is the Interactivity API refresh target; the screen-reader status element announces updated result counts after filter interactions - Loading state uses
aria-busy="true"on the item container (CSS-only skeleton) - Filter controls use
<form method="get">with proper<label>,<fieldset>, and<legend>elements - No-JS fallback: all filters perform a full page reload, preserving all functionality without JavaScript
- Query Results — the required child block that renders iterated items
- Query Pagination — numbered, load-more, and infinite-scroll pagination
- Query Filter — checkbox, select, search, sort, active-filters, and reset controls
- Query Group Header — group label rendered once per group
- No Results — content shown when the query returns zero items
- Slider — can act as an item host for carousel-style query output
- Scroll Slides — can act as an item host for scroll-driven query output
Auto-generated from
docs/blocks/QUERY.md. To update, edit the source file and changes will sync on next push to main.
- Accordion
- Advanced Heading
- Blobs
- Breadcrumbs
- Card
- Chart
- Comparison Table
- Countdown Timer
- Counter Group
- Divider
- Dynamic Image
- Fifty Fifty
- Flip Card
- Form Builder
- Grid
- Hotspot
- Icon
- Icon Button
- Icon List
- Image Accordion
- Map
- Modal
- Modal Api Reference
- Modal Auto Triggers
- Modal Fse Compatibility
- Modal Gallery Navigation
- Modal Trigger
- Pill
- Product Categories Grid
- Product Showcase Hero
- Progress Bar
- Query
- Query Filter
- Query Group Header
- Query No Results
- Query Pagination
- Query Results
- Row
- Scroll Accordion
- Scroll Marquee
- Scroll Slides
- Section
- Section Divider
- Slider
- Star Rating
- Sticky Sections
- Table Of Contents
- Tabs
- Text Path
- Timeline
- Background Video
- Block Animations
- Clickable Group
- Conditional Visibility
- Custom Css
- Draft Mode
- Dynamic Tags
- Expanding Background
- Grid Mobile Order
- Grid Span
- Hover Effects
- Max Width
- Responsive Visibility
- Reveal Control
- Scroll Parallax
- Sticky Header
- Style Binding
- Svg Patterns
- Text Alignment Inheritance
- Text Reveal
- Abilities Api
- Abilities Api Guide
- Block Bindings
- Draft Mode Api
- Form Webhooks
- Generation Contract
- Interactive Blocks
- Layout Flexibility
- Markdown Content Negotiation
- Rest Api Reference
- Wp Cli Reference
- Ai Assisted Development
- Best Practices Summary
- Block Controls Organization
- Block Development Best Practices Comprehensive
- Block Exclusion Guide
- Deploying To Wordpress Org
- Design System
- 2026 04 16 Blocks Editor Ux Design
- 2026 04 17 Theme 3 Inspector Ia
- 2026 04 21 Query Block Onboarding
- 2026 04 21 Query Capable Layout Blocks Design
- 2026 04 27 Block Roadmap Ideas
- 2026 07 01 Shape Divider Theme Inheritance
- 2026 07 02 Icon Block Dynamic Render Pilot
- 2026 07 06 Section Divider Block Design
- 2026 07 06 Section Style Variations Fse Design
- 2026 07 06 Section Styles Editor Preview
- 2026 07 07 Row Grid Overlay Hover Parity Design
- 2026 07 21 Conditional And Dup Label Sourcing
- 2026 07 23 Theme Block Type Animation Defaults
- 2026 08 16 Chart Block
- 2026 08 16 Greenshift Gap Roadmap
- 2026 08 17 Woocommerce Surface
- 2026 08 24 Loop Carousel
- 2026 08 24 Star Rating Block
- 2026 09 17 Abilities Drift Prevention
- 2026 09 17 Abilities Drift Prevention Implementation
- 2026 09 29 Existing User Regression Fixes
- 2026 09 29 Release Preflight Fixes
- Readme
- 2026 07 02 Block Authorability Audit
- 2026 09 29 Regression Fixes
- 2026 09 29 Release 2.9.0
- 2026 09 29 Release Fixes
- 2026 10 19 Bug Hunt
- 2026 10 20 Bug Hunt Round 2