5th Jan '24
/
0 comments

Meta Box Relationship in Bricks using Posts Query Loop

This Pro tutorial is similar to the recent ACF Relationship in Bricks using Posts Query Loop guide but for Meta Box.

In the past, we covered a somewhat custom requirement in the Meta Box Relationship in Bricks tutorial.

If your requirements are fairly standard, though, i.e., you are looking to show posts connected to a different CPT when viewing single posts of a particular CPT, a query type of your Meta Box relationship does the job. This feature is built into Bricks.

This tutorial covers a different method of showing related posts when using a Meta Box relationship with a posts query type.

A post of Game CPT:

On the front end:

(ignore the numbers in the brackets after post title links; they are post IDs for testing purposes)

'Review 3' post:

Step 1

Install and activate Meta Box and Meta Box AIO.

Create both your CPTs. In this example, these are game and review.

Add a few posts of each.

Step 2

Create a Relationship like this:

Step 3

Edit posts of any of your above CPTs and select connected items of the other post type.

Remember that in Meta Box, the relationship is bidirectional by default.

Step 4

Create a single Bricks template for your first CPT (game in the current example) and edit it with Bricks.

Add a template condition to make it apply to singular games.

Add a Section inside its Container, Post Title and Post Content elements.

Add another Section and inside its Container, a h2 Heading having "Related Review" text.

We shall programmatically append "s" to this heading text if there is more than 1 connected review.

Add a Container and inside it a Block. Enable query loop on the Block.

Set Post Type to Reviews.

Enable "Query editor (PHP)".

Paste:

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
Meta Box Group’s Number Sub Field Values Sum

Meta Box Group’s Number Sub Field Values Sum

In the Bricks Facebook group a user asked: We can define a custom function that takes a Meta Box group ID, the sub field ID…
Categories:
Tags:
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
Filtering Bricks Query Loop By Meta Box Relationship

Filtering Bricks Query Loop By Meta Box Relationship

In the Bricks Facebook group a user asks: Consider this setup: CPTs: Service Areas and City Pages Meta Box Relationship: City Pages to Service Areas…
Categories:
Pro
Meta Box Color Picker to CSS Custom Property Workflow in Bricks

Meta Box Color Picker to CSS Custom Property Workflow in Bricks

This Pro tutorial provides the steps to declare a custom property (CSS variable) whose value is equal to the post-specific color set via a custom…
Categories:
Tags:
Pro
Filtering posts by a group field’s subfield value with Meta Box when using a custom table in Bricks

Filtering posts by a group field’s subfield value with Meta Box when using a custom table in Bricks

Filtering a query loop to output only those posts with the value of a Select subfield of a Group field set to Yes when using…
Categories:
Tags:
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…