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

Related Tutorials..

Pro
Programmatically populating ACF field values in WordPress

Programmatically populating ACF field values in WordPress

An example of how to set the values of a Select-type field with the names and labels of all public post types.
Categories:
Pro
ACF Font Awesome Field in Bricks

ACF Font Awesome Field in Bricks

We walk through using the Advanced Custom Fields: Font Awesome Field plugin for showing Font Awesome icons.
Categories:
Tags:
Pro
Customizing ACF Repeater/Relationship or Meta Box Relationship Query Parameters in Bricks

Customizing ACF Repeater/Relationship or Meta Box Relationship Query Parameters in Bricks

For query types other than post, term and user in Bricks i.e, ACF Repeater/ACF Relationship/Meta Box Relationship there are no built-in controls for modifying the…
Categories:
How to create parallax effects using Rellax.js in Bricks

How to create parallax effects using Rellax.js in Bricks

This tutorial provides the JS & PHP codes that can be pasted in order to create smooth parallax effects using the Rellax.js library inside Bricks…
Categories:
Pro
Upcoming Events Grouped by ‘Month Year’ in Bricks

Upcoming Events Grouped by ‘Month Year’ in Bricks

A custom query loop type for showing future events based on a date custom field using three nested query loops.
Modifying ACF Field Value Before It Is Output

Modifying ACF Field Value Before It Is Output

Consider the scenario where a Page has a "Page Fields" field group created with ACF Pro like this: Field name: scientific_coordinators (type Repeater)|__ Sub field…
Categories:
Pro
ACF Image Data in Bricks

ACF Image Data in Bricks

Displaying Alt text, Caption, Title and URL of an ACF image field for posts in a query loop.
Categories:
Tags:
Pro
Filtering ACF Relationship Query by Post Meta in Bricks

Filtering ACF Relationship Query by Post Meta in Bricks

How to filter the posts of a post type related to another post type based on the value of a True / False type ACF…