Patterns & Query Loops
Expressions are context-aware. Whether a block lives on a standalone page, inside a reusable Pattern, or within a Query Loop iteration, every post, user, and site reference resolves against the context where the block is actually rendered — not where it was authored.
Block Patterns
A Block Pattern is a reusable group of blocks that can be inserted into any page or template. Expressions inside a pattern automatically adjust to the post, user, and site context of wherever the pattern is placed.
Why This Matters
Write a pattern once with expressions like {{ post.title }} or {{ user.name }}, and it will display the correct values on every page it appears — no per-page configuration needed. This applies to both synced and unsynced patterns.
Example: Member Welcome Card
Create a Pattern containing:
- A Heading with:
{{ user.name }} - A Paragraph with:
{{ user.meta.bio | default "You haven't written a bio yet." }} - A Group with Class Injection:
{{ post.type }}-welcome-card
Insert this pattern on any page and the expressions resolve to the current visitor’s data and that page’s post type automatically.
Query Loops
Vector Expressions is fully compatible with the Query Loop block. Any block nested inside a Query Loop automatically resolves expressions against the current iteration’s post — not the parent page.
How the Loop Context Works
On the frontend, no special handling is needed. WordPress’s Query Loop block calls setup_postdata() for each iteration, which sets the global post. The post data root reads this global naturally, so every expression resolves against the correct post automatically.
In the editor, the Query Loop provides each inner block with a postId through block context. Vector Expressions reads this context to hydrate the correct post data for live expression previews.
You do not need to do anything special — just write your expressions normally and they will resolve to the correct post in both the editor and the frontend.
Example: Dynamic Post Cards
Imagine a Query Loop containing a Group block with:
- A Paragraph block bound to:
{{ post.author_name | upper }} • {{ post.date | date "F j, Y" }} - A List block with your custom meta fields
{{ post.meta.amenity }} - A Group block with Class Injection:
{{ post.meta.card_type | match event="card--event" course="card--course" default="card--standard" }}
Every card in the loop will render with its own correct data automatically.
Accessing Custom Fields Per Post
Use post.meta.* to access custom fields for each post in the loop:
{{ post.meta.price | default "Contact for pricing" }}
{{ post.meta.is_featured ? post.meta.badge_label : "" }}
Patterns Inside Query Loops
Patterns and Query Loops compose naturally. Place a Pattern inside a Query Loop and its expressions resolve to each iteration’s post — giving you a reusable card template with zero duplication.
Performance
Expression ASTs are cached by hash. If the same expression appears on every card or pattern instance (which is typical), it is parsed once and the cached AST is reused for every occurrence. Only the resolved values differ per context.