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 626 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…
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
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:
Pro
Conditionally Outputting Query Loop Item Based on Post Meta in Bricks

Conditionally Outputting Query Loop Item Based on Post Meta in Bricks

Rendering query-loop enabled posts depending on the value of each post's custom field value is tricky because by default, the custom field plugins' functions or…
Categories:
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:
Pro
Bricks Forms + Meta Box: Auto-Create Post Relationships on Form Submission

Bricks Forms + Meta Box: Auto-Create Post Relationships on Form Submission

How to link a Bricks post-creation form on a post to a newly created post of another post type using Meta Box relationship.
[Function] Current Term Has Children

[Function] Current Term Has Children

Updated on 20 Jul 2024 A user asks: I'm working on an archive template for WooCommerce products. I'm trying to hide a section if there…