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 624 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

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
Dynamic Source for Video Element in Bricks Using Meta Box Post Field

Dynamic Source for Video Element in Bricks Using Meta Box Post Field

This Pro tutorial provides the steps to set the source of a Bricks video element on single CPT pages to be the URL of a…
Categories:
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
Sorting ACF Relationship Posts by Date Meta in Bricks

Sorting ACF Relationship Posts by Date Meta in Bricks

Consider the following setup: CPT: Events ACF Fields:Event Date Information (Group)|__Event Date (Date Picker)Pick Sub Events (Relationship) An Event can have 1 or more related…
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
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: