Skip to main content

Query Terms

This page covers how to query taxonomy terms — categories, tags, and custom taxonomies.

Basic usage

Paste this directly into the query arguments editor in the Loop block's sidebar:

[
'taxonomy' => 'category',
'number' => 10,
'orderby' => 'name',
]

Common arguments

Arguments follow the WP_Term_Query API — any argument it accepts works here too.

ArgumentDescriptionExample
taxonomyTaxonomy name'category', 'post_tag'
hide_emptyHide terms with no poststrue, false
orderbySort field'name', 'count'
orderSort direction'ASC', 'DESC'
numberLimit results10
parentParent term ID, 0 for top-level0
child_ofAll descendants of a term12
includeInclude specific IDs[1, 2, 3]
excludeExclude specific IDs[4, 5]
slugFilter by slug(s)'news'

More query examples

Category navigation

[
'taxonomy' => 'category',
'hide_empty' => true,
'orderby' => 'name',
]

Top categories by post count

[
'taxonomy' => 'category',
'orderby' => 'count',
'order' => 'DESC',
'number' => 5,
'hide_empty' => true,
]

Top-level product categories

[
'taxonomy' => 'product_cat',
'hide_empty' => true,
'parent' => 0,
]

Tag cloud

[
'taxonomy' => 'post_tag',
'orderby' => 'count',
'order' => 'DESC',
'number' => 20,
'hide_empty' => true,
]

Child terms of a parent

Use in a nested Loop block where parent is the outer loop's data alias:

[
'taxonomy' => 'location',
'parent' => parent.id,
]

Template examples

In the HTML inspector, the Loop block uses get_terms() syntax. Query arguments are managed by the sidebar — the inspector shows get_terms() with empty parentheses to keep the template readable.

Category filter with active state

<nav class="filter-bar">
<a href="/blog/" class="{{ not archive.term ? 'active' : '' }}">All</a>

{% for term in get_terms() %}
<a href="{{ term.link }}" class="{{ archive.term.id == term.id ? 'active' : '' }}">
{{ term.name }}
</a>
{% endfor %}
</nav>

Category index with posts

{% for term in get_terms() %}
<section>
<h2>{{ term.name }}</h2>

{% for post in get_posts() %}
<a href="{{ post.link }}">{{ post.title }}</a>
{% endfor %}
</section>
{% endfor %}
Common mistake

hide_empty defaults to true in WordPress. If you're not seeing terms you expect, check whether they have published posts assigned. Set 'hide_empty': false to include empty terms.

Next steps

  • Term provider — all fields available on term items
  • get_posts() — query posts filtered by taxonomy
  • Loop — loop concept and data sources