Consider this scenario:
Custom Post Types:
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.
- Members and Orders
- Orders and Trainings
- 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.
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.
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.
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.
This is a BricksLabs Pro tutorial.
For full access login below or create your BricksLabs Pro account