Query Compare To Relationship

Hi, I have two CPT UIs Custom User and Ability.
The Custom User is a post type and not a WordPress User!
For each Custom User post you can set a set of relationships pointing toward a Ability post.

When viewing a Custom User post I set up a query to show the Abilities which the User contains, which is working.
By selecting Ability as post type and creating a Meta Query.
The meta query has a dynamic Meta Compare field as following:

Now I also want to show in a Ability post which Users possess that Ability and this is not working.
As post type I selected Custom User for displaying some User fields.
And for the meta query the following:
Meta key: rability because I want to compare that to the current post.
Meta value: I would like to select the current post, but not sure how to, so the error is probably here?
Meta Compare: = because every entry found should be the same.

I tried multiple combinations but couldn’t find a solution :frowning:

Hi @T-low,

ACF Relationship querying should work. I take it that you are using a primary query with a nested query inside the query template.
Did you try setting the Meta Compare to LIKE for rability?

Hi @Louis,
thank you for the reply.

As the first example, when I am in a Custom User post, the ACF Relationship querying is working perfect. :+1:

Not quite sure about the query template :thinking:
Im in a Ability post.
primary query: looking for all Custom Users by setting my Post Type to Custom Users?
nested query: my meta query?

The = and LIKE both deliver the same result. They display all Custom Users, which haven’t any assigned Ability post.

Edit: In a Custom User post the RAbility Relationship can possess multiple Ability posts.

Hi @T-low,

Maybe I’m misunderstanding here, but can you confirm that you are using 2 query blocks?
One being the main query and the second one, placed inside the Query Template block, to process the relationship?

Hi @Louis,

I am using a single query block. I thought the further query would be done in the meta tab?

Hi @T-low,

Not if you want to query the relationship for every single item within the primary query, otherwise the post id will not be correct. That is how ACF recommends doing it: ACF | Querying relationship fields

Thank you for the link @Louis,

I am not really good with code. But isn’t this just a normal query block?

This is exactly what I’m looking for, but I don’t know how to integrate the value field. :thinking:

Hi @Louis,
I tried different solution and it probably all boils down, that as mentioned I still do not know how to add a current post as a query meta value field.


Hi @T-low,

You will need 2 Query blocks.

One main one and then another one querying your meta field and value.
The second one has to be within the first one’s Query Template block, so that it gets repeated and can pick the correct Post ID.

From what I see further up this isn’t the case.

Hi @Louis,
thank you for your reply.
I tried solving the problem with 2 Query blocks, but was not able to find a solution. Doubting my comprehension of these queries… seems that I do not understand this problem. :smiling_face_with_tear:
Not quite comfortable asking to be spoonfed this problem, but would it be possible to fill in the image below with the “Doctor/Locations” ACF Solution that you linked before?

Wanted to continue here…hence a small bump from me :wink:

Hi I am working on a similar project. I am new here, this is my first week. My question is did you ever figure this out? I was already on the right track by adding a second query in my primary query, but I am unclear on how and what settings to use to pull the related information. My relationships is bi relational… meaning i am not sure there is a parent child, they are synced. I am trying to pull in an imave from teh related post type into the first post type query loop. Almost there but i cant figure out the settings for the second query loop. By the way it is great that we can in fact add additional query loops to a primary this opens up endless possibilities. I also am not good with code. i can copy past and manipulate as directed btu that is the extent of my coding abilities so i am looking for a settings solution or a completed code snippet to past.

Hi @ShannaKae,

this problem was solved.
I created some Query examples over here: DALE: The “Doctor And Location Example” With Solutions For Queries, Relations & Other Stuff

I just saw that this specific problem was not displayed there, but this post Query for ACF relation should give you an answer :wink: