15th Jan '23
/
4 comments

ACF Relationship in Bricks

Update on 3 Jan 2024: You may also be interested in this newer tutorial.

This Pro tutorial walks through setting up and using an ACF Relationship type of field in Bricks.

We are going to set up a bidirectional relationship between an event CPT (Custom Post Type) and venue CPT, then see how related venue(s) can be shown on single event pages and related event(s) on single venue pages.

Editing an event (Event 1):

Editing the venue that's set for the above event (Venue 1):

The related event (Event 1) will automatically show up. Event 3 has been added manually. Any changes done here will get reflected in the corresponding events.

A single event on the front end:

A single venue on the front end:

We shall also ensure that

  1. the Section having the related events/venues get output only if there's at least 1 published related event/venue.
  2. heading inside the Section says Events or Event depending on whether there are/is more than 1 or 1 related event and similarly, Venues or Venue.

Step 1

Create both the CPTs using a plugin like CPT UI or otherwise.

Step 2

Create a ACF field group for one of the CPTs (doesn't matter for which you do first) having a Relationship field.

In the "Filter by Post Type" field, select the other CPT.

Step 3

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..

Bricks single mode – Limiting the number of posts to 1 in the editor

Bricks single mode – Limiting the number of posts to 1 in the editor

Creating a "Single Mode" for Bricks query loops to make sure only one post is rendered in the builder.
Pro
Google Maps JavaScript API in Bricks

Google Maps JavaScript API in Bricks

This Pro tutorial provides the steps to show post-specific maps with custom marker content in Bricks using Google's Maps JavaScript API and Advanced Custom Fields.…
Categories:
Pro
Querying Posts by Date/Datetime Custom Fields in Bricks

Querying Posts by Date/Datetime Custom Fields in Bricks

This Pro tutorial shows how to configure ACF and Meta Box to query posts in Bricks by custom field(s) of the type Date/Date Time Picker…
Categories:
Tags:
Color Custom Field as Section Background Color on Category/Term Archives in Bricks

Color Custom Field as Section Background Color on Category/Term Archives in Bricks

How to use a color from a taxonomy term custom field for as the hero section background color on archive pages.
Categories:
Tags:
Pro
Custom Dynamic Data Tags for ACF Field Label, Prefix and Suffix in Bricks

Custom Dynamic Data Tags for ACF Field Label, Prefix and Suffix in Bricks

Bricks lacks built-in dynamic tags for ACF field labels, prefixes, and suffixes. This tutorial shows how to add them using custom dynamic tags.
Categories: