Skip Navigation

[Resolved] Bi-directional relationship

This support ticket is created 7 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.

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 J S 7 years, 6 months ago.

Assisted by: Luo Yang.

Author
Posts
#522344

J S

I am trying to: create a true bi-directional relations between two different custom post types.

I have two CPTs -> Schools and Documents each with their own custom fields. I will be pre-populating the school data via importing 5,000 schools and their fields in a CSV file.

I need to set this up so that when someone creates a new document (in a front-end form), they can select a school, the school data is then linked to the document and able to be displayed on the document page. But, I also need the document (or list of documents if many are entered) to be displayed on the school pages.

Is it possible to set this up so that if I add a new document and select a school that the document relates to, the school will also show the document automatically without having to edit the school to link to the document as well manually?

How do I go about this?

#522405

Dear J S,

How do you setup the "bi-directional" post type relations?
For example, if the post type "Documents" is a child post type of "Schools", then there is a custom field "_wpcf_belongs_schools_id" in each child "Documents" post, which stores the value of parent "Schools" post ID, see our document:
https://toolset.com/documentation/user-guides/querying-and-displaying-child-posts/
section "Displaying child posts using Types PHP functions"
You will need to manually setup the field "_wpcf_belongs_schools_id" values in the CSV file

#524260

J S

Wonderful. Thank you!