Help! Querying Relationship on CPT Template

I need help please, with querying an ACF relationship field on a single CPT template.

Here’s the scenario:
I have two Custom Post Types (CPTs) - “Branches” and “Services”. These two CPTs are linked by an ACF relationship field, allowing me to choose which services are related to a branch and vice versa.
The “Services” CPT has a taxonomy called “Service Category”, which includes categories like Massages, Facials, Nail Care, etc. This structure allows me to group the service posts.

I’ve created a single template for the “Branches” post type. On this template, I aim to display the “Service Category” taxonomy and list the related services linked to a branch under the taxonomy.

The problem:
As depicted in the photo, the relationship loop is displaying, but it’s showing for all the taxonomies. The service posts were properly assigned to their respective taxonomy in the backend.

Thank you so much.

So a branch is a location. That’s simple.

Your list makes it look like Foot Massage is a service in the Massage category. Am I following that correctly?

I don’t think you can build your list w/o a custom function. The data flow is wrong.

  • You have the branch.
  • You use the branch to get the related services.
  • When you loop thru the services, you only have access to 1 service’s taxonomy terms at a time.

So you could make a list of the services with the category.

You have to juggle some data to make this list the way you want it. You have an array of services each with a related category. You need an array of categories with related services.

I’d loop thru the services to build an array like

$categories => array(
    'massages' => array(
        'foot',
        'elbow'
    ),
    'facials' => array(
        'classic facial',
        'something else'
    )
)

Doable but custom.