29th Dec '22
/
1 comment

Indirect Meta Box Relationship in Bricks

This Pro tutorial shows how to modify a Bricks' query loop parameters to only show the posts of a CPT that is indirectly related to the current single CPT item when using Meta Box.

Consider this scenario:

Custom Post Types:

  • Members
  • Orders
  • Trainings

Requirement: On a single member page, show all the related posts of training. Note that there is no direct relationship between member CPT and training CPT.

Relationships:

  • Members and Orders
  • Orders and Trainings

Sample posts:

  • Training 1 Connected From Order 2.
  • Training 2 Connected From Order 1 and 2.
  • Training 3 Connected From Order 1.
  • Member 1 Connected To Order 1.
  • Member 2 Connected To Order 2.

Objective:When viewing Member 1, show trainings 2 and 3. This is because Member 1 is connected to Order 1 and this order is connected to Training 2 and Training 3.

Screenshots:

Relationship: Orders and Trainings

Relationship: Members and Orders

We are also going to ensure that the Section in which the indirectly related CPT items are output gets rendered only if there is at least 1 such published CPT item.

Step 1

Create a Bricks template named say "Single Member" of type "Single".

Edit it with Bricks.

Add a Template setting condition for applying the template to Members CPT.

Add a Section having Post Title and Post Content.

Add another Section having a "Related Training" Heading. We are going to dynamically add "s" at the end of this heading text if there's more than one published indirectly-related training for the current member.

Add a Container having a Block.

Enable Query Loop on the Block. Select Trainings CPT.

Add a Post Title inside the Block.

At this stage, all the training CPT items will be output.

Step 2

Add the following in child theme's functions.php (w/o the opening PHP tag) or a code snippets plugin:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 610 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Bidirectional Relationship between a CPT and a Taxonomy of another CPT using ACF in Bricks

Bidirectional Relationship between a CPT and a Taxonomy of another CPT using ACF in Bricks

A couple of members asked: I have a cpt called "Markets" aand a cpt "tools". Tools have a taxonomy "tools group". How can i create…
Pro
Posts from Random Categories in Bricks

Posts from Random Categories in Bricks

Updated on 31 Jul 2023 In BricksLabs Facebook group a user asked: How would you query 3 WordPress posts from 3 different categories with Brick…
Meta Box Category Colors in Single Posts

Meta Box Category Colors in Single Posts

Looking to use Meta Box Color Picker fields' values in a single post Bricks template based on the post category? This tutorial shows how. Note:…
Categories:
Tags:
Pro
Nested Meta Box Query Loop Inside a CPT Query Loop in Bricks

Nested Meta Box Query Loop Inside a CPT Query Loop in Bricks

This Pro tutorial provides the steps for setting up a cloneable Meta Box group query inside a CPT query in Bricks. Scenario: CPT: course Meta…
Categories:
Pro
Meta Box Related Project’s Featured Image URL on Single Reviews

Meta Box Related Project’s Featured Image URL on Single Reviews

Updated on 26 Jun 2025 In a recent website I worked on, a requirement was to get the URL of the featured image of a…
Pro
Dynamic Post-specific Templates in Bricks using Meta Box/ACF Select Field

Dynamic Post-specific Templates in Bricks using Meta Box/ACF Select Field

Update on 23 Aug 2023: Added steps for ACF. Bricks builder v1.8.4 introduced an pretty useful filter called bricks/active_templates that flew under the radar. This…