ACF Relationship search

I have reviewed the previous posts and tried a few of the suggestions but can’t seem to return a result.

I have a CPT - client that has an ACF relationship field connecting to multiple posts in another CPT - contacts (please note there is no ACF relationship field in the contacts CPT).

Whilst in one of the Contacts CPT Posts I am wanting to reference some info from the Client CPT post.

I have looked at using the current post id as a search criteria but don’t seem to get a result.

I tried filters and If statements but don’t seem to get any results.

Any ideas would be welcome, Thanks

If I understand correctly what you’re trying to do, I think you’ll want to look into filtering by field. Unlike the regular loop’s custom_field parameter, that field attribute supports all the same conditional logic comparisons as the If tag. That means that you can write something like this, which would loop through only the posts that include some data inside an ACF relationship field that matches the current contact post ID.

<Loop type=client field=my_acf_relationship_field field_compare=includes field_value="{Field id}">
  <Field some_field_from_the_matching_clients />
</Loop>

If you want to read some more about how to think about passing the context of your L&L markup from one post to another, you might want to check out this article I wrote.

1 Like

Hi Ben,

That worked - thank you so much - and that article has given me some further context on another bit I was looking at.

1 Like