For the complete documentation index, see llms.txt. This page is also available as Markdown.

Working with relational fields inside query loops

Learn how to use relational fields in Bricks loop

Relational, 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:

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:

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

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:

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:

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:

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.

Last updated