19th Jul '24
/
0 comments

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 a relation between Market (cpt) and tool group (taxonomy). My goal is to display related market inside the tool group (taxonomy) archive. Thanks

Hi, I have a CPT=“Product” with a taxonomy=”Product-group” and a CPT=”Team member”. Is it possible to link Team member and product-group with a bi-directional relation using ACF? And then ouput the related product group inside team member single template? It would be great if you're able to help me with this! Many thanks in advance!

This Pro tutorial walks through the process of setting up a bidirectional relationship between posts of a CPT and a custom taxonomy of another CPT and outputting the items of related object(s) on the single CPT pages and term archive pages in Bricks using ACF.

Scenario covered in this tutorial: Team Member <-> Product Category.

Product Category is a taxonomy for another CPT (Product).

Sample Team Member posts:

After implementing the tutorial, 'Employee A' post on the front end:

'Employee B' post on the front end:

'Decor' product category archive in the backend:

On the front end:

'Music' product category archive in the backend:

On the front end:

We shall also ensure that the Sections get output only if there is at least one related item (CPT post or taxonomy term).

Step 1

Install and activate ACF.

Create your CPT.

Ex.:

Create the other CPT and an associated taxonomy. In our dev site, we used product CPT and product_cat taxonomy that come with WooCommerce.

Step 2

Create a field group for your main CPT (team-member in this example).

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
How to Update Custom Fields with Default Values For Existing Posts when using ACF

How to Update Custom Fields with Default Values For Existing Posts when using ACF

Let's take a scenario where there are 10 Pages in a WordPress site. You proceed to create a Text-type of custom field called, say, "Custom…
Categories:
Tags:
Pro
Merging ACF Gallery Images with Featured Image in Bricks

Merging ACF Gallery Images with Featured Image in Bricks

Updated on 12 Mar 2025 In the Bricks Facebook group a user asks: Merging images from different fields into a single gallery Hi, I have…
Categories:
Pro
Events grouped by Event Date custom field in Bricks

Events grouped by Event Date custom field in Bricks

This Pro tutorial for Bricks users provides the steps to output posts of an event custom post type dynamically grouped by the value of their…
Categories:
Pro
Configuring Image Gallery dynamic source in Bricks

Configuring Image Gallery dynamic source in Bricks

Let's say you have a custom field created with ACF Pro of the type Gallery called "Property Gallery" for posts of "Property" CPT. In the…