6th Feb '24
/
2 comments

Filtering ACF Relationship Query by Post Meta in Bricks

This Pro tutorial provides the steps to filter the posts of a post type related to another post type based on the value of a True / False type ACF field in Bricks.

Consider this scenario:

  • Practitioners CPT
    • Practitioners Therapy Relationship field
  • Therapies CPT
    • Associated Practitioners Relationship field
    • Active? True / False field

The requirement is to list all the Practitioners on a Page with their corresponding or related therapies but only those not marked inactive.

Practitioners List:

Therapies List:

Output after implementing the tutorial:

Step 1

Create your CPTs.

Create field groups for each.

Practitioner Fields:

Therapy Fields:

Step 2

Add Practitioner and Therapy CPT entries.

Edit any CPT's entries and select the related items of the other CPT. Since the relationships have been set to be bi-directional, the other post type's Relationship field will automatically get populated.

Edit your therapies and update those that should be inactive using the True / False type custom field.

A therapy marked as inactive:

Another therapy that is NOT marked inactive (default state):

Step 3

Edit the Page where you'd like to show the practitioners' grid with Bricks.

Set it up like this:

Outer query loop:

Set the Posts per page to a large number.

Inner query loop:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 609 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
CPT Submenu Items in ACF Pro Options Admin Menu

CPT Submenu Items in ACF Pro Options Admin Menu

This Pro tutorial provides the steps to add links to admin pages under an Options page created with ACF Pro. All code mentioned in this…
Pro
ACF Relationship Select Filter in Bricks

ACF Relationship Select Filter in Bricks

In the BricksLabs Facebook group, a user asks: I'm learning about ACF relationships and attempting to output a list of posts on any given page,…
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.
ACF Checkbox Items with Custom SVG Bullets in Bricks

ACF Checkbox Items with Custom SVG Bullets in Bricks

We walk through outputting list items with SVG icons based on the choice of a ACF Checkbox field.
Categories:
Tags:
Pro
Conditional Rendering of ACF Repeater Rows Based on True / False Sub Field in Bricks

Conditional Rendering of ACF Repeater Rows Based on True / False Sub Field in Bricks

This Pro tutorial provides the steps to modify a ACF Repeater query loop to only output the rows for which a True / False type…
Categories:
Pods Relationship Field in Bricks

Pods Relationship Field in Bricks

In this Pro tutorial, we explore the Relationship field of Pods and share ways to output items of a related post type incl. the associated…
Categories:
Pro
ACF Relationship: Show all other events related to the artists of the current event

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

How all other events related to the artists of the current event can be output in a Bricks query loop.
Categories: