Skip Navigation

[Resolved] Restrict Post Relationship Fields to single instance

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

Problem:

Say I have a Many to Many Relationship that links CPTs People and Cities. There is a Post Relationship Field called Type (checkboxes) which specifies the person's connection to the City. (Born, Lived, Current)

Is there any way I can restrict it so that only one City can be connected as Born and Current, whereas many can be connected for Lived?

Solution:

You can setup two one-to-many relationships between post type "City" and "People":

- Born

- Current

Then when your user edit a single "People" post, he can:

- related only one "City" post in relationship "Born"

- related only one "City" post in relationship "Current"

Relevant Documentation:

This support ticket is created 6 years, 1 month 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 3 replies, has 2 voices.

Last updated by Luo Yang 6 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#1122314

Ben

I am trying to achieve the following.

Say I have a Many to Many Relationship that links CPTs People and Cities. There is a Post Relationship Field called Type (checkboxes) which specifies the person's connection to the City. (Born, Lived, Current)

Is there any way I can restrict it so that only one City can be connected as Born and Current, whereas many can be connected for Lived?

Is there any way to do this within one Relationship by some form of restriction on each option? Or would it only be able to be achieved by using a One to Many Relationship for Born and Current, and a separate Many to Many Relationship for Lived?

#1122601

Hello,

Yes, you are right, you can setup two one-to-many relationships between post type "City" and "People":
- Born
- Current

Then when your user edit a single "People" post, he can:
- related only one "City" post in relationship "Born"
- related only one "City" post in relationship "Current"

#1123844

Ben

Thank you for clarifying Luo Yang.

#1124131

You are welcome