Skip Navigation

[Resolved] Check if relationship exists between two particular posts

This thread is resolved. Here is a description of the problem and solution.

Problem:

I want to check if a relationship exists between a given parent post and a given child post.

Solution:

It is possible within Views plugin, for example, you can create a post view, see details here:

https://toolset.com/forums/topic/check-if-relationship-exists-between-two-particular-posts/#post-1175085

Relevant Documentation:

This support ticket is created 5 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by John Johansen 5 years, 11 months ago.

Assisted by: Luo Yang.

Author
Posts
#1174889

Tell us what you are trying to do?
I want to check if a relationship exists between a given parent post and a given child post.
Please note that this is NOT to check whether ANY child posts exist for the given parent post.
Please also note that this question is related to, but not the same as, another question about outer joins in post relationships.

Is there any documentation that you are following?
Toolset Relationship document.

Is there a similar example that we can see?
No, but I can describe what I am trying to do.
I have two custom post types, Patrons and Locations. I created a many-to-many relationship between them, where Patrons is the 'parent' and Locations is the 'child'.'
If I know the ID of a Patron entry and the ID of a Location entry, can I determine whether there is a relationship set between them?
What is the link to your site?

hidden link

#1175085

Hello,

It is possible within Views plugin, for example, you can create a post view:
- Query posts of post type "Locations"
- Filter by:
a) Select posts in a Patrons Locations relationship that are related to "Specific Patrons post".
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-many-related-items
b) Include only posts with the following IDs: 123(Specific location post ID)
https://toolset.com/documentation/user-guides/filtering-views-query-by-post-id/

Then it will be able to check if "Specific Patrons post" is related with "Specific location post ID"

In section "Loop Editor", within [wpv-items-found] ... [/wpv-items-found], display text as what you want.

#1175132

My issue is resolved now. Thank you!