Skip to main content

Query Items

This page covers how to loop over raw data — static arrays, ACF repeater fields, or any dynamic data — using get_items().

Unlike get_posts(), get_terms(), and get_users(), this function doesn't query the database. It wraps existing data so you can loop over it.

Basic usage

{% for item in get_items([{'name': 'Home', 'url': '/'}, {'name': 'About', 'url': '/about'}]) %}
<a href="{{ item.url }}">{{ item.name }}</a>
{% endfor %}

Inline arrays

Array of objects

Each object becomes an item with named properties:

{% for item in get_items([
{'name': 'Home', 'url': '/'},
{'name': 'About', 'url': '/about'},
{'name': 'Contact', 'url': '/contact'}
]) %}
<a href="{{ item.url }}">{{ item.name }}</a>
{% endfor %}

Simple values

When items are plain strings or numbers, item is the value itself:

{% for item in get_items(['Home', 'About', 'Services', 'Contact']) %}
<li>{{ item }}</li>
{% endfor %}

Numbered items

{% for item in get_items([0, 1, 2, 3, 4]) %}
<div class="slide slide-{{ item }}"></div>
{% endfor %}

ACF repeater fields

Pass a repeater field value to loop over its rows:

{% for item in get_items(post.meta('team_members')) %}
<div class="member">
<h3>{{ item.name }}</h3>
<p>{{ item.position }}</p>
</div>
{% endfor %}

Nested repeaters

{% for section in get_items(post.meta('sections')) %}
<h2>{{ section.title }}</h2>

{% for item in get_items(section.items) %}
<p>{{ item.text }}</p>
{% endfor %}
{% endfor %}

Real-world patterns

Custom navigation menu

{% for item in get_items([
{'label': 'Home', 'url': '/', 'icon': 'home'},
{'label': 'Products', 'url': '/products', 'icon': 'shop'},
{'label': 'Blog', 'url': '/blog', 'icon': 'pen'},
{'label': 'Contact', 'url': '/contact', 'icon': 'mail'}
]) %}
<a href="{{ item.url }}" class="nav-link">
<span class="icon icon-{{ item.icon }}"></span>
{{ item.label }}
</a>
{% endfor %}
{% for item in get_items([
{'name': 'Twitter', 'url': 'https://twitter.com/yourhandle', 'icon': 'twitter'},
{'name': 'GitHub', 'url': 'https://github.com/yourhandle', 'icon': 'github'},
{'name': 'LinkedIn', 'url': 'https://linkedin.com/in/yourhandle', 'icon': 'linkedin'}
]) %}
<a href="{{ item.url }}" aria-label="{{ item.name }}" class="social-link">
<span class="icon icon-{{ item.icon }}"></span>
</a>
{% endfor %}

Feature list from custom fields

{% for item in get_items(post.meta('features')) %}
<div class="feature">
<h3>{{ item.title }}</h3>
<p>{{ item.description }}</p>
</div>
{% endfor %}

Pricing table

{% for item in get_items([
{'name': 'Starter', 'price': '9', 'features': '5 projects, 1GB storage'},
{'name': 'Pro', 'price': '29', 'features': 'Unlimited projects, 50GB storage'},
{'name': 'Enterprise', 'price': '99', 'features': 'Everything, priority support'}
]) %}
<div class="pricing-card">
<h3>{{ item.name }}</h3>
<span class="price">{{ item.price }} €/mo</span>
<p>{{ item.features }}</p>
</div>
{% endfor %}

FAQ accordion from repeater

{% for item in get_items(post.meta('faq')) %}
<details>
<summary>{{ item.question }}</summary>
<p>{{ item.answer }}</p>
</details>
{% endfor %}
{% for item in get_items(post.meta('gallery')) %}
<figure>
<img src="{{ item.image }}" alt="{{ item.caption ?? '' }}">
{{ item.caption ? '<figcaption>' ~ item.caption ~ '</figcaption>' : '' }}
</figure>
{% endfor %}

Testimonials

{% for item in get_items(post.meta('testimonials')) %}
<blockquote class="testimonial">
<p>{{ item.quote }}</p>
<footer>
<strong>{{ item.author }}</strong>
{{ item.role ? ', ' ~ item.role : '' }}
</footer>
</blockquote>
{% endfor %}
Common mistake

get_items() is for data you already have. If you need to query posts from the database, use get_posts() — not get_items() with a list of post IDs.

Next steps

  • Loop — loop concept and data sources
  • get_posts() — query posts from the database