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

Related Tutorials..

Limiting the Query Loop Posts Output to Post IDs From a Custom Field in Bricks

Limiting the Query Loop Posts Output to Post IDs From a Custom Field in Bricks

A user asks: Recently Bricks introduced the PHP query editor that lets us modify the query parameters right within the query dialog of the builder…
Categories:
Tags:
Pro
Filtering ACF Relationship Query by Post Meta in Bricks

Filtering ACF Relationship Query by Post Meta in Bricks

How to filter the posts of a post type related to another post type based on the value of a True / False type ACF…
Pro
Meta Box Taxonomy Field’s Image Value in Posts

Meta Box Taxonomy Field’s Image Value in Posts

In a project I am currently working on, the requirement is to show the image of an "Image Advanced" type attached to a taxonomy in…
Categories:
Tags:
Pro
Conditionally outputting an element in a Query Loop based on date-type custom field

Conditionally outputting an element in a Query Loop based on date-type custom field

This Pro tutorial shows how to output an element in a Bricks' query loop only if the value of a date-type of custom field for…
Categories:
Pro
Bidirectional Relationship between a CPT and a Taxonomy of another CPT using ACF in Bricks

Bidirectional Relationship between a CPT and a Taxonomy of another CPT using ACF in Bricks

A couple of members asked: I have a cpt called "Markets" aand a cpt "tools". Tools have a taxonomy "tools group". How can i create…
Pro
Meta Box Settings Fields in Bricks

Meta Box Settings Fields in Bricks

This Pro tutorial is the equivalent of our earlier ACF Options Fields in Bricks article but when using Meta Box. While retrieving the values of…
Categories:
Tags: