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), as in WordPress: post by default, 'any' for the post types in search | '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' |
Post types WordPress shows nowhere to the public (no pages of their own, left out of search) are dropped from post_type, unless opened in Settings > Privacy. Without post_type, a search finds the post types included in search, and a filter on terms of a custom taxonomy finds the post types that use it, as in WordPress. When you set post_status, each viewer only gets the posts they're allowed to read: a private post shows only to users who can read it; a loop of drafts, pending or scheduled posts lists those the viewer can edit (an author their own, an editor everyone's), and mixed with published posts, only to users who can edit everyone's posts.
| 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 editor, the loop and its pagination show what the page shows on your site: in a template, a page that uses it, such as the News archive for a category-news template or the latest product for single-product. The 404 template shows no posts.
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'],
],
]