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
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…
Pods Relationship Field in Bricks

Pods Relationship Field in Bricks

In this Pro tutorial, we explore the Relationship field of Pods and share ways to output items of a related post type incl. the associated…
Categories:
Pro
Conditional Rendering Based on Current Date and Time in Bricks when Using Meta Box

Conditional Rendering Based on Current Date and Time in Bricks when Using Meta Box

A Pro member of our site asks: Using bricks + Meta, conditionally show a post listing under 3 different conditions, based on the Current Date…
Pro
Bricks Dynamic Condition – Check if today falls within 5 days before any holiday date

Bricks Dynamic Condition – Check if today falls within 5 days before any holiday date

Creating a custom condition that returns true or false depending on whether today falls within 5 days before any holiday dates selected on a Meta…
Categories:
Tags:
Random Meta Box Image

Random Meta Box Image

Displaying a random image from a set of images from a Meta Box Images Advanced-type field.
Categories:
Tags:
Pro
Meta Box Checkbox List Query Type in Bricks

Meta Box Checkbox List Query Type in Bricks

This Pro tutorial provides the steps to add a new query type in Bricks builder for displaying the values of a Checkbox List type of…
Categories: