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

Related Tutorials..

Pro
Meta Box Image Advanced Field Images in Bricks Query Loop

Meta Box Image Advanced Field Images in Bricks Query Loop

Updated on 3 Feb 2025 A user asked: Do you know what the best way to query an image from metabox gallery? I would like…
Categories:
Tags:
Custom Image Field Avatar in WordPress

Custom Image Field Avatar in WordPress

Learn how to use a Meta Box image field value as the author profile image on single post pages in WordPress/Bricks.
Categories:
Tags:
Pro
Meta Box Related Project’s Featured Image URL on Single Reviews

Meta Box Related Project’s Featured Image URL on Single Reviews

Updated on 26 Jun 2025 In a recent website I worked on, a requirement was to get the URL of the featured image of a…
Pro
User Role Condition in Bricks

User Role Condition in Bricks

This Pro tutorial provides the steps to conditionally output elements depending on the currently logged-in user's role. Step 1 Create a section Template having the…
Categories:
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:
How to conditionally load your scripts based on an ACF field

How to conditionally load your scripts based on an ACF field

This tutorial provides the PHP codes that can be pasted in order to enqueue your scripts conditionally based on the value of an ACF field…
Categories: