Skip Navigation

[Resolved] Select a parent post in a new child post form

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

Problem: I would like to allow Users to select the parent post in a new child post Form.

Solution: When you create a new child post Form, the parent post select field will be generated automatically.

Relevant Documentation: https://toolset.com/documentation/post-relationships/selecting-parent-posts-using-forms-create-child-items/

This support ticket is created 6 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by coc-admin 6 years, 6 months ago.

Assisted by: Christian Cox.

Author
Posts
#922546

Tell us what you are trying to do? In an Add or Edit "My Surplus Items" form, use the related "Departments" post type to populate options for the Surplus-Department drop-list.

Is there any documentation that you are following? I've looked into the Relationships documentation. But that seems to depend on both posts already existing. I would rather select the related Department at the time I'm adding a new Surplus form. Is there a better method to use instead?

Is there a similar example that we can see?

What is the link to your site?

#922710

Hi, to set a many-to-many (M2M) relationship between a new post and an existing post, multiple forms are required. It is not currently possible to create a post and also specify its related M2M posts in the same Form, unfortunately. It is possible for one-to-many (O2M) relationships, though. When creating new child posts using Forms, you can select an existing parent post and establish the relationship at the same time you create the child post.

To accomplish both things in a new post Form with an M2M relationship, you would have to use custom code. If you're comfortable writing PHP you may be able to use a generic field to select one of the related posts, and use the Post Relationships API to connect the posts programmatically. We have information about this API available here:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/

#922950

I just need a 1-to-many, not M2M (thankfully!). I will look for that documentation. Thanks!