Skip Navigation

[Resolved] Getting related posts based on two many to many post relationships

This support ticket is created 3 years, 7 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/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 3 years, 7 months ago.

Assisted by: Waqar.

Author
Posts
#2061097

hey i have a many to many relationship between clinic, doctors and positions and im trying to get the doctors who connected to the current clinic with the specific position

$query = new WP_Query(
array(
'post_type' => 'doctor',
'posts_per_page' => -1,
'toolset_relationships' => array(
array(
'role' => 'child',
'related_to' => 26344,
'relationship' => 'clinic-position-doctor'
),
array(
'role' => 'child',
'related_to' => get_the_ID(),
'relationship' => 'clinic-doctor'
)
),

)
);

but on the results im getting the doctor that is related to the clinic as well but with a different position. how can i fix that?

#2063773

Hi,

Thank you for waiting and sorry about the delay in getting back.

I've performed some tests on my website and noticed that there are certain limitations involved in your current setup, to achieve what you're planning.

> 'one doctor must be have multiple positions in multiple clinics. For example one doctor is a manager in Clinic A but on clinic B is a visitor doctors'

In Toolset, more than one post-relationship connection can't exist between two posts, which means that if you'll connect 'Doctor A' with 'Position XYZ' in the scope of 'Clinic 1', you won't be able to join the same doctor with the same position, for any other clinic.

A single post-relationship connection can represent or hold information about only two participants, whereas for your requirement, you need three (doctor, clinic, and position).

To overcome this, I'll recommend dropping the 'Position' custom post type and instead add a 'Position' as a custom field, in the intermediary post that is generated as a result of the many-to-many relationship, between 'Doctors' and 'Clinics'.

This way, whenever you'll join a Doctor and a Clinic, you'll have the option to specify what position he/she occupies, which will make all 3 items available, within a single relationship connection.

I hope this makes sense and please let me know if you have any follow-up questions.

regards,
Waqar