Skip Navigation

[Closed] Self-join relationship for Post Types (I need a self-join relationship feature)

This support ticket is created 3 years, 6 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.

Our next available supporter will start replying to tickets in about 0.71 hours from now. Thank you for your understanding.

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: Africa/Casablanca (GMT+01:00)

This topic contains 14 replies, has 2 voices.

Last updated by Jamal 3 years, 6 months ago.

Assisted by: Jamal.

Author
Posts
#2055827

Post Types for Relationship
I need a self-join relationship feature
''Connecting posts of the same type is not supported yet.'' I am getting this message
This feature is very urgent for me,
especially listing-listing relationship,
When will you activate this feature. I would be very happy if you give at least ETA in this regard.

I would like to create two directory lists as doctors and hospitals. There is a many-to-many relationship between doctors and hospitals.
but I can't create this yet with the toolset toolkit.
How do you suggest a solution until you activate the above feature in the toolset.
I wish you good work.
Regards,
Dr Etem SANLIER

#2056121

Hello and thank you for contacting the Toolset support.

Indeed, the same custom post-type relationships are not supported yet. We intend to support them in an upcoming release. But, that's probably for the next year. We can't really give an ETA, because it may change based on different factors, and we wouldn't like to break a promise 🙂

However, if I understood well your request, two custom post types will be a good solution. Doctors custom post type, and Hospitals custom post type. And you can create a relationship between them. Either one-to-many or many-to-many relationships.

If you provide more details on what you want to build, we may give more accurate advice.

#2056141

Thank you Jamal, for the answer,
I have been waiting for this feature for more than 2 years. And you said that you have been working on it for more than two years and will release this feature as soon as possible, based on other people's questions about it. I hope this feature will be activated as soon as possible without waiting too long.
During this time, I will define my problem and I will be glad if you help for a solution.

I would like to create two directory lists as doctors and hospitals. There are many-to-many relationships between doctors and hospitals.

doctors and hospitals both in a directory listing theme listing Page.
Doctors and Hospitals are both different from each other as the listing page is only the listing type.
and I want to establish a very very relationship between both listing pages.
Best Regards,
Dr Etem SANLIER

#2056655

I am not sure to understand what did you mean by:
doctors and hospitals both in a directory listing theme listing Page.
Doctors and Hospitals are both different from each other as the listing page is only the listing type.
and I want to establish a very very relationship between both listing pages.

Let me give some information on how WordPress and Toolset will offer out of the box, and you can provide more details about the specifics of your project.
Let's start with two custom post types:
- Doctors: With slug "doctor".
- Hospitals: With slug "hospital".

By default, archives will be enabled for the custom post types, unless you disable them in the custom post type definition(Toolset->Post Types->Edit(when hovering over a post type)). This means that:
- hidden link : will display the archive page of doctors. A loop of published doctors. It will use the archive template assigned to doctors if available.
- hidden link : will display the archive page of hospitals. A loop of published hospitals. It will use the archive template assigned to hospitals if available.
- hidden link : will display the doctor post with slug "watson". It will use the content template assigned to doctors if available.
- hidden link : will display the doctor post with slug "amsterdam". It will use the content template assigned to hospitals if available.

Now, if you need to display related posts, usually, you will need to create a view:
- To display the list of hospitals where Dr. Watson works, inside its single post page (hidden link), you will need to create a view.
- To display the list of doctors that work in the Amsterdam hospital, in its single post page(hidden link), you will need to create a view.
Check this article https://toolset.com/course-lesson/displaying-related-posts/

Archives are generated by WordPress, they are somehow predefined. Views, on the other hand, provide more flexibility. You can create a view inside an archive template, a content template, a post, a page. And you can define what would the view display(one custom post type, multiple post type). You can build a view inside a /listing/ page that displays, both the hospitals and the doctors.

I hope this gives some guidance. Let me know if you have any questions or if you would like to provide more details about your use case.

#2056679

Thank you Jamal
The listing type of hospitals and doctors is not different
listing type for both
hidden link:
hidden link:
How do I establish a many-to-many relationship between two identical list types.
What solution can I solve temporarily
Etem SANLIER
Best Regards,

#2056689

Well, it is not possible to have the same slug (listing) for two post types. It may be implemented with some workarounds and hacks, but that's not how WordPress works and it is better not to force it.

Another solution would be to use a custom post type "Listing" for both doctors and hospitals. You can use a custom taxonomy or a custom field(listing type) to differentiate between doctors and hospitals. I would suggest a custom taxonomy, as it will be faster in views and archive templates.

Because we can't have the same post type relationships, we can create another post type and use two one-to-many relationships. Let's call this post type "Assignement". We can then have two one-to-many relationships as follow:
- Doctors relationship: One Listing can have multiple assignments, one assignment can only have one parent listing.
- Hospitals relationship: One Listing can have multiple assignments, one assignment can only have one parent listing.
For example, the "Assignement" post with the title "Dr. Watson - Amsterdam", is linked to Dr. Watson in the "Doctors relationship". And is linked to "Amsterdam" in the "Hospitals relationship".

With this structure we can:
- Display the list of hospitals for Dr. Watson, on its page hidden link it will require a view of assignments posts, and we will display the data from its parent hospital post.
- Display the list of doctors for Amsterdam, on its page hidden link in the same way, it will require a view of assignments posts, and we will display the data from its parent doctor post.

However, please note that views filters and queries do not support filtering with multiple relationships. For example, we can't filter for the assignment posts for a specific doctor and a specific hospital. It will require some workarounds. We can discuss that on a separate ticket if you need it.

I hope this makes sense. Let me know if you have any questions.

#2060931

Hello Jamal,
Yes I need the solution and code you suggest
somehow, I have to associate doctors and hospitals of the same listing type with each other very-many times.
So there are many hospitals where docs work,
they also have multiple doctors in their hospitals.
I wish you good work.

#2063871

Awesome, thank you for your feedback.

However, I don't see anything else to add here.

Please let me know if something from my earlier messages is not clear or if you still need assistance here. Otherwise, please mark this ticket as resolved and open a new ticket for any other question or request.

All the best!

#2063965

Hello there
yes i still need help
how can I temporarily establish the relationship between the same list type,
Or somehow how can I show their doctor on the hospital's lisitng page
I wish you good work

#2063987

Sure, I'll do my best to help.

You can't establish the relationship between the same list type 🙂 You will need an additional post type and use two one-to-many relationships.

Please read this reply carefully, and let me know if anything is not clear https://toolset.com/forums/topic/self-join-relationship-for-post-types-i-need-a-self-join-relationship-feature/#post-2056689

#2064351

Hello there
I'm telling you insistently, but you don't understand me.
I can't use a different list type because of thema features. I need the relation attribute for the same list type.
When exactly will you update.
Or can you suggest me a remedy. Somehow I need to list the doctors on the hospital pages.
Can you suggest a similar solution in the attached links?
https://toolset.com/forums/topic/self-join-relationship-expected-release-date/
https://toolset.com/forums/topic/need-to-group-post-type-by-a-parent-of-the-same-type/
I wish you good work

#2064441

The solutions suggested in the referred tickets consist of custom code, which is out of the scope of the support forum. We may help with simple cases, but for complex cases, you will need to hire a developer if you are not comfortable with programming.
- https://toolset.com/toolset-support-policy/

Instead of a solution that will require custom code, I have suggested, in an earlier reply, another solution that does not require any custom code. The solution consists of an additional custom post type and two relationships. Maybe it is just a misunderstanding or a language barrier. I already explained how to do it, but it seems that you did not understand it fully. So, I am creating an example for you on this test site
Please login with this URL hidden link

Both hospitals and doctors are posts from the same custom post "Listing". I added a custom field "Listing type" to differentiate between doctors and hospitals. And also to use it in conditionals inside the content template:
- hidden link

Because we don't have self joins, we'll use an additional custom post type. I created this custom post type hidden link

Then, I created two relationships. Check them here hidden link hidden link

Then, I created two posts in the assignment Post type and connected the doctors with the hospitals. Check this screenshot hidden link

Then I created a content template and used two views inside of it. Each view is inside a conditional block. One view is meant to return the hospitals, and the other one is meant to return the doctors. This is the content template hidden link

Please note that the views are looking for the assignment posts, each one with the appropriate relationship. Check this hidden link
And we pull the information from the parent post, in the other relationship, instead of the current post. Check this screenshot hidden link

I hope this explains better the workaround that I have suggested in my reply https://toolset.com/forums/topic/self-join-relationship-for-post-types-i-need-a-self-join-relationship-feature/#post-2056689

And check the results here, both doctors are "assigned" to the same hospital:
- Doctor: hidden link
- Doctor: hidden link
- Hospital: hidden link

#2064607

dear jamal, Thanks
thank you for the detailed answer,
I will examine your solution in detail and try to apply it.
I wish you good work
Best Regards,
Dr.EtemSANLIER

#2064609

dear jamal
thank you for the detailed answer,
I will examine your solution in detail and try to apply it.
I wish you good work
Best Regards,
Dr. Etem SANLIER

#2064919

Thank you very much for your feedback. I'll set this thread as waiting for your reply, it should be kept open for a couple of weeks. And you will get an email notification before it gets closed automatically by the system.

Please note, that the test site will be removed after 7 days. If you can't use it during that period, please take this Duplicator package that I've prepared. hidden link

The topic ‘[Closed] Self-join relationship for Post Types (I need a self-join relationship feature)’ is closed to new replies.