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

Instant access to 390+ Bricks code tutorials with BricksLabs Pro