Basic Relationship Loop#
{{ related_posts }} <article> <h2><a href="{{ url }}">{{ title }}</a></h2> <p>{{ excerpt }}</p> </article>{{ else }} <p>No related posts.</p>{{ /related_posts }}Inside the loop, built-in post values refer to the related post.
Post Values#
Common values inside relationship loops include:
| Value | Meaning |
|---|---|
{{ id }} | Related post ID. |
{{ title }} | Related post title. |
{{ excerpt }} | Related post excerpt. |
{{ content }} | Related post content. |
{{ url }} | Related post URL. |
{{ permalink }} | Related post URL. |
{{ featured_image }} | Related post featured image URL. |
{{ featured }} | Related post featured image URL. |
{{ date }} | Related post date. |
{{ author }} | Related post author. |
Parent Context#
Use parent to read from the outer post:
{{ related_posts }} <h2>{{ title }}</h2> <p>Parent page: {{ parent.title }}</p>{{ /related_posts }}Nested relationship or repeater loops can use parent.parent to go farther up.
Taxonomies Inside Relationships#
Taxonomy loops inside a relationship can read terms from the related item:
{{ related_posts }} <article> <a href="{{ url }}">{{ title }}</a> {{ categories }} <span>{{ name }}</span> {{ /categories }} </article>{{ /related_posts }}When ACF Local JSON includes taxonomy data, TemplateX can compile those loops more directly.