Query Posts
This page covers how to query posts, pages, and custom post types.
Basic usage
Paste this directly into the query arguments editor in the Loop block's sidebar:
[
'post_type' => 'post',
'posts_per_page' => 6,
]
Common arguments
Arguments follow the WP_Query API — any argument it accepts works here too.
| Argument | Description | Example |
|---|---|---|
post_type | Post type(s) | 'post', 'page' |
posts_per_page | Number of posts, -1 for all | 10 |
orderby | Sort field | 'date', 'title', 'rand' |
order | Sort direction | 'ASC', 'DESC' |
post_status | Post status | 'publish' |
category_name | Category slug, comma for OR | 'news' |
tag | Tag slug | 'featured' |
post__in | Include specific IDs | [1, 2, 3] |
post__not_in | Exclude specific IDs | [4, 5] |
author | Author ID | 1 |
s | Search term | 'keyword' |
Main query inheritance
Enable Inherit Query in the Loop block's sidebar to use the main WordPress query. This is how you build archive templates, search results, and custom post type archives. No query arguments needed — the loop uses whatever query WordPress already resolved for the page.
In the HTML inspector, this displays as:
{% for post in posts %}
Taxonomy filtering
Filter by category or tag slug directly:
[
'post_type' => 'post',
'category_name' => 'news',
'tag' => 'featured',
]
Use tax_query for advanced filtering — multiple taxonomies, AND/OR logic:
[
'post_type' => 'product',
'tax_query' => [
'relation' => 'AND',
['taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => 'shoes'],
['taxonomy' => 'product_tag', 'field' => 'slug', 'terms' => 'sale'],
],
]
Meta filtering
Filter by a single meta value, or use compare and type for numeric comparisons:
[
'post_type' => 'product',
'meta_query' => [
['key' => 'price', 'value' => 100, 'compare' => '>', 'type' => 'NUMERIC'],
],
]
Combine multiple conditions with relation:
[
'post_type' => 'product',
'meta_query' => [
'relation' => 'AND',
['key' => 'on_sale', 'value' => '1'],
['key' => 'stock', 'value' => 0, 'compare' => '>', 'type' => 'NUMERIC'],
],
]
Ordering
By field — title, menu_order, date, rand:
[
'post_type' => 'page',
'orderby' => 'menu_order',
'order' => 'ASC',
]
By meta value — use meta_key with meta_value or meta_value_num:
[
'post_type' => 'event',
'meta_key' => 'event_date',
'orderby' => 'meta_value',
'order' => 'ASC',
]
More query examples
Any argument value can be a dynamic expression — use post.id, post.categories[0].slug, or any data field instead of a static value.
Related posts by category
Exclude the current post, match its first category:
[
'post_type' => 'post',
'category_name' => post.categories[0].slug,
'post__not_in' => [post.id],
'posts_per_page' => 3,
]
Child pages of the current page
[
'post_type' => 'page',
'post_parent' => post.id,
'orderby' => 'menu_order',
'order' => 'ASC',
'posts_per_page' => -1,
]
Template examples
In the HTML inspector, the Loop block uses get_posts() syntax. Query arguments are managed by the sidebar — the inspector shows get_posts() with empty parentheses to keep the template readable.
Blog card grid
{% for post in get_posts() %}
<article>
<img src="{{ post.thumbnail.src('medium') }}" alt="{{ post.thumbnail.alt ?? post.title }}">
<h2><a href="{{ post.link }}">{{ post.title }}</a></h2>
<p>{{ post.excerpt({words: 20}) }}</p>
<time>{{ post.date('M j, Y') }}</time>
</article>
{% endfor %}
WooCommerce product grid
Uses a Variable block to access found_posts and pagination before and after the loop:
{% set products = get_posts() %}
<p>{{ products.found_posts }} products</p>
{% for product in products %}
<div class="product-card">
<img src="{{ product.thumbnail.src('medium') }}" alt="{{ product.thumbnail.alt ?? product.title }}">
<h3>{{ product.title }}</h3>
<span class="price">{{ product.price|currency }}</span>
</div>
{% endfor %}
{{ products.pagination }}
posts_per_page: -1 returns every matching post. On a site with thousands of posts, this slows down the page significantly. Always set a reasonable limit unless you truly need all results.
Next steps
- Pagination — add page navigation
- Post provider — all fields available on post items
- get_terms() — query categories, tags, and custom taxonomies
- Variable block — store queries for pre-loop access