11th Jul '24
/
0 comments

ACF Relationship: Show all other events related to the artists of the current event

Consider the following scenario when using ACF in Bricks:

CPTs: event and artist.

Event CPT has a Relationship field named event__related_artists.

Artist CPT has a Relationship field named artist__related_events.

Both fields are bidirectional.

This Pro tutorial shows how all other events related to the artists of the current event can be output in a Bricks query loop.

Event CPT field group

Artist CPT field group

Note that both the relationship-type fields' return format is at the default, Post Object.

Setting the fields to be bidirectional

Editing an event post

Sample data

Artist 1: Event A

Artist 2: Event B, Event C

Artist 3: Event C, Event A

After implementing the tutorial

From the sample data we can see that Event C is related to Artist 2 and Artist 3.

The events related to Artists 2 and 3 are Event A, B and C.

When Event C is being viewed on the front end, the output shows Events A and B as expected and Event C is set to be excluded since it is the current post.

Step 1

Create both your CPTs and their corresponding field groups.

Create the Relationship-type fields in each and enable bidirectional relationships.

Edit the posts of any of your post types and select the related post of the other post type.

Step 2

Create and edit a Bricks template called "Event" (going by the current example).

Add a template condition so it applies to singular posts of event CPT.

Set it up like this:

For the query loop, choose Events post type.

Enable PHP editor and paste:

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
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…
How to create filters with IsotopeJS in Bricks (Part 3): apply multiple filters

How to create filters with IsotopeJS in Bricks (Part 3): apply multiple filters

This tutorial will review how to apply multiple filters to an isotope container using the IsotopeJS library‘s features in Bricks.
Pro
ACF Repeater Row Count Condition in Bricks

ACF Repeater Row Count Condition in Bricks

This Pro tutorial provides the steps to output elements on single posts (of any post type) in Bricks only if a specific ACF Repeater-type of…
Categories:
How to populate a map with dynamic markers from a CPT using ACF in Bricks (PART 1)

How to populate a map with dynamic markers from a CPT using ACF in Bricks (PART 1)

This tutorial provides the PHP & JS codes that can be pasted in order to create a dynamic map with markers populated from a custom…
Categories:
Pro
Filtering ACF Repeater Bricks Query Loop by Sub Field Value

Filtering ACF Repeater Bricks Query Loop by Sub Field Value

We look into how ACF Repeater rows output by a Bricks query loop can be filtered using the bricks/query/run PHP filter.
Categories:
Pro
Filtering Bricks Query Loop By Meta Box Relationship

Filtering Bricks Query Loop By Meta Box Relationship

In the Bricks Facebook group a user asks: Consider this setup: CPTs: Service Areas and City Pages Meta Box Relationship: City Pages to Service Areas…
Categories: