This Pro tutorial provides the steps to conditionally render elements in a single template of a CPT depending on the value of a
- regular custom field
- 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:
DisabledandEnabled) - 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:
- 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.
- 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