> For the complete documentation index, see [llms.txt](https://docs.acpt.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.acpt.io/integrations/bricks-builder/working-with-relational-fields-inside-query-loops.md).

# Working with relational fields inside query loops

Learn how to use relational fields in Bricks loop

[Relational](/meta-fields/field-types/relational-field.md), Post Multiple, Term Multiple, and User Multiple fields are fully compatible with Bricks Builder query loops.

### Simple query loops

All you need to do is select the field as the query loop source inside the container.

The posts, terms, or users will be retrieved automatically.

Here’s an example:

<figure><img src="https://3235524095-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fiyf0tSKPgXiyoQ3zV3I6%2Fuploads%2FqSbMiJQaYgasNzdYPIY9%2FIndiana-Jones-and-the-last-crusade-Builder--11-14-2025_11_29_AM.png?alt=media&amp;token=fed68c7c-e546-498f-addb-f0cebce5221e" alt=""><figcaption></figcaption></figure>

In this example, we have a single movie template.

I'm looping through the movie-associated pages stored in the `box_pages` ACPT field. Within this post loop, I can use the standard syntax to access ACPT page fields.

### Bidirectional relations

Let's see an example.

First of all, suppose you have a CPT called **movie** and another one called **post**.

Set up a **one-one bidirectional** relation between movies and posts.

You'll have something like this:

<figure><img src="https://3235524095-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fiyf0tSKPgXiyoQ3zV3I6%2Fuploads%2Fgit-blob-198e184807e4e11097ce75920ddae03a6f9d19dd%2FSchermata%20del%202024-06-14%2018-51-07.png?alt=media" alt=""><figcaption></figcaption></figure>

Now, move to the Bricks builder editor.

To fetch all the posts from the above relational field value, you need to set a query loop adding a **custom meta query**:

* **meta keys:** the name of the movie meta field
* **value:** {post\_id}
* **operator**: LIKE

<figure><img src="https://3235524095-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fiyf0tSKPgXiyoQ3zV3I6%2Fuploads%2Fgit-blob-f904d1623e31c5add7ebc7888de42a067865b5f5%2FSchermata%20del%202024-06-14%2018-51-43.png?alt=media" alt=""><figcaption></figcaption></figure>

In this case, only one post will be fetched, since the relational is one-one.

### Through-relationship tags (inline access without a nested loop)

When looping CPT A, you can access fields that belong to a *related* CPT B (or even B → C) inline — no nested query loop required.

ACPT registers **through-relationship tags** automatically for every POST\_TYPE relational field. The tag uses a **double-underscore** (`__`) separator between the source field slug and the target field slug:

```
{acpt_[source_field_slug]__[target_field_slug]}
```

#### Example

Suppose you have:

* CPT **Movie** with a Post relational field `director` pointing to CPT **Director**
* CPT **Director** with a text field `director_name`

While looping Movies in Bricks, you can display the director's name inline with:

```
{acpt_director__director_name}
```

No additional query loop on Director is needed.

#### Two-hop chains (A → B → C)

Through-relationship tags support up to **2 hops**. If Director also has a relational field `agency` pointing to CPT **Agency** (which has a field `agency_city`), you can reach it from the Movie loop with:

```
{acpt_director__agency__agency_city}
```

#### Constraints

* Only **POST\_TYPE** relational fields are supported as the traversal step.
* For **MANY-type** relations (one-to-many, many-to-many) the **first** related entity is used. If you need to iterate over all related items, use a nested query loop instead.
* Complex field types at the terminal position are not supported: Repeater, Flexible Content, List, and Clone fields cannot be the final field in a through-relationship tag.
