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

Related Tutorials..

Pro
Conditional Output Based on ACF Date Field in Bricks

Conditional Output Based on ACF Date Field in Bricks

Updated on 1 Aug 2024 Looking to have a Section or other elements in Bricks rendered on the frontend only if today's date is before…
Categories:
Pro
ACF Term Meta on Single Posts in Bricks

ACF Term Meta on Single Posts in Bricks

Consider this scenario: CPT: Project Custom taxonomy: Project Type Each project will be assigned only one project type. Project Type taxonomy's custom field: Project Type…
Categories:
ACF Relationship: Count of Related Posts

ACF Relationship: Count of Related Posts

Looking to get the number of CPT B posts related to a CPT A post when using a Relationship field with ACF? Here's a custom…
Categories:
Tags:
ACF Repeater Sub Field Values as Tabs in Bricks

ACF Repeater Sub Field Values as Tabs in Bricks

Bricks' query loop supports ACF Repeaters and Meta Box Groups out of the box besides posts, users and terms. This tutorial shows how we can…
Categories:
Tags:
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…
Pro
Outputting ACF Repeater’s Sub Fields

Outputting ACF Repeater’s Sub Fields

This Pro tutorial provides the code for printing custom HTML after looping through rows of a ACF Repeater (available in ACF Pro) that has a…
Categories: