15th Jul '25
/
2 comments

Getting Field Values from a Connected CPT when using Meta Box Relationship in Bricks

This Pro tutorial provides the steps to conditionally render elements in a single template of a CPT depending on the value of a

  1. regular custom field
  2. subfield of a cloneable Group field

of a CPT connected to the current post via a Meta Box relationship.

Here's the scenario we are working with:

CPT 1: Award WinnerCPT 2: Property Development

Relationship: Award Winners -- Property Development

An Award Winner post will only be related/connected to one Property Development post at the most.

Custom fields for Property Development:

  • property_development_nearby_institutions_option (Select field with these choices: Disabled and Enabled)
  • property_development_facilities_group (Group field set to cloneable)
    • property_development_facility_name (Text subfield)

View/template in question: Single Award Winner post pages.

Requirements:

  1. Create a custom function that returns the value of the given field of the Property Development post that's connected to the current Award Winner post.
  2. Create a custom function that returns a boolean (true or false) depending on whether there is at least one row of the given subfield of the given group field of the Property Development post that's connected to the current Award Winner post.

Step 1

Add the following in child theme's functions.php (w/o the opening PHP tag) or a code snippets plugin:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 614 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Meta Box Category Colors in Single Posts

Meta Box Category Colors in Single Posts

Looking to use Meta Box Color Picker fields' values in a single post Bricks template based on the post category? This tutorial shows how. Note:…
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:
Check if a given category has at least one post

Check if a given category has at least one post

There could be situations where you want to check if a given category (by its slug) has at least 1 post assigned to that category.…
Categories:
Pro
How to Insert Element(s) Between Query Loop Posts in Bricks

How to Insert Element(s) Between Query Loop Posts in Bricks

Update on 16 Aug 2023: Follow this tutorial instead. This Pro tutorial shows how we can insert a Div (or any custom HTML) after nth…
Pro
Custom Meta Box Thumbnail Slider in WordPress

Custom Meta Box Thumbnail Slider in WordPress

This Pro tutorial provides the steps to set up an image and YouTube video thumbnail slider in WordPress using Splide and Meta Box. The site…
Categories:
Tags:
Bricks Condition for WishList Member

Bricks Condition for WishList Member

How to render a Bricks element only if the user has access to a specified WishList Member level.
Categories:
Pro
Check If The Latest Post Was Published in The Last X Minutes

Check If The Latest Post Was Published in The Last X Minutes

In this Pro tutorial we shall define a custom function that takes in the number of minutes as an argument and returns true if there…
Categories: