Skip to main content

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.

ArgumentDescriptionExample
post_typePost type(s)'post', 'page'
posts_per_pageNumber of posts, -1 for all10
orderbySort field'date', 'title', 'rand'
orderSort direction'ASC', 'DESC'
post_statusPost status'publish'
category_nameCategory slug, comma for OR'news'
tagTag slug'featured'
post__inInclude specific IDs[1, 2, 3]
post__not_inExclude specific IDs[4, 5]
authorAuthor ID1
sSearch 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.

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 }}
Common mistake

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