Skip Navigation

[Resolved] How to link to related posts in New Post Form and Edit Post Form?

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

Problem: Is it possible to connect posts in a many-to-many relationship, in a Form that creates new posts or edits existing posts? Is it possible to create new posts in a Relationship Form that links many-to-many posts?

Solution: At this time, many-to-many (M2M) relationships cannot be managed in a Post Form, and posts cannot be created in a Relationship Form. The two operations must be performed in separate forms. You may be able to accomplish some of these goals with custom code and the Forms API and Post Relationships API.

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/

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

Last updated by reneV-2 6 years, 7 months ago.

Assisted by: Christian Cox.

Author
Posts
#914841

I have added four CPTs to my site, each of which can be in a many-to-many relationship with the others:
1) 'Harmful strategies'
2) 'Governance gaps'
3) 'Counter strategies'
4) 'Examples'

The first relationship form I have created links 'Examples' to 'Harmful strategies' (and vice versa). I have also created a New Post Form and Edit Post Form for 'Examples'.

Now there are three things that I need to achieve, but can not get working:
1) When creating a new 'Example', users should be able to add related 'Harmful strategies' from the frontend - preferably while filling out the form for adding a new 'Example', and not after submitting the new 'Example'.
2) When editing an existing 'Example', users should be able to add or delete related 'Harmful strategies' right from the frontend form.
3) Finally, in the ideal world, users should also be able to create a new 'Harmful strategy' while creating a new 'Example' or editing an existing 'Example'. But I am not sure whether this is possible with Toolset.

Could you please explain to me how to set this up?

At the moment, both things are possible from the WP backend, but we do not want to give users access to the backend because it confuses them.

I have read through all the relevant documentation I could find in the Support section, but could not find the answer.

The URL of my site is: hidden link
Please log in with user: toolset-mtg, password: #Sarphati30

The New Post Form for an Example is: hidden link
The page where this New Post Form is embedded is: hidden link

The Edit Post Form for an Example is: hidden link

A list of previously added Examples can be found at: hidden link

The relationship form to link Examples to Harmful strategies is: hidden link

Many thanks for helping out!

#914959

Hi, at this time combinations of those 3 actions are not possible in individual Forms. A Create Post or Edit Post Form cannot create or edit M2M relationships, or create or modify posts in another post type. Similarly, a relationship Form cannot create or modify posts. You may be able to accomplish some of these goals with custom code utilizing the Forms API and Post Relationships API:
https://toolset.com/documentation/programmer-reference/cred-api/
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/

I agree there is some room for improvement here, so feel free to submit a new Request ticket to suggest improvements to the new Forms plugin. Our developers will review your suggestion for feasibility and decide whether or not to implement it.

#915236

Hi Christian, many thanks for getting back! It is a pity this is not (yet) possible with Forms, so I will definitely file a request ticket. It would be really helpful for people who need to migrate from Pods or Gravity Forms.

Given that I am not a programmer, I am trying to work out a short-term solution that is not too difficult to implement.

Suppose we switch from M2M to O2M relationships (e.g. one Harmful strategy can have multiple Examples, but one Example can not be linked to multiple Harmful strategies), would that enable us to:
1) link a new Example to an existing Harmful strategy with the Create Post Form for Examples and/ or Harmful strategies,
2) link an existing Example to an existing Harmful strategy with the Edit Post Form for Examples and/ or Harmful strategies,
3) delete the link between an existing Example to an existing Harmful strategy with the Edit Post Form?

Hope to hear from you soon.

#915410

When creating or editing a child post, you can add a link, edit a link, or remove a link to an existing parent post. It is not possible to create parent posts, delete parent posts, or edit parent posts in any other way in a child post form.

When creating or editing a parent post, you can only affect the parent post's information. You cannot create new child posts, edit existing child posts, delete child posts, or add/remove/modify links to child posts from a parent post form.

#916148

Thanks!

#916290

Dear Christian,

Unfortunately, I continue to run into a problem with linking children to a parent post. I hope you can help me with this, as it is a crucial feature of our new site.

I set up a one-to-many relationship between CPT 'Harmful strategies' and CPT 'Examples'. I created a Relationship Form for this relationship, and added a link to the Relationship Form in the Edit Post form for 'Harmful strategies'.

Here's an example of the Edit Post Form: hidden link

Under the header 'Related Examples' there is a link 'Connect an existing example' which points to the relationship form: hidden link

However, clicking on this link continues to generate the following error: "This relationship form no longer exists".

I completely rebuilt the relationship and relationship form, and double checked the shortcodes, but the problem persists.

(I also set up a staging site, but that one does not contain the latest version of these forms, and I do not want to overwrite it with the content I created in production, as your colleague Nigel is currently investigating a separate issue there).

Many thanks for your help / advice!

René

#916305

Hi, I'm not able to load the site right now to test this out. I asked another colleague in a different location to test as well, and we're both unable to log in. Can you check the site and let me know when I can test?

#916355

Hi Christian, I am sorry about that. Just to be sure, I have created a new admin user. Could you please try again to log in

#916381

Okay the issue I see is that you're trying to use Relationship Forms to manage the connection between posts in a one-to-many relationship. The workflow for one-to-many relationships is a bit different in that you can only manage those when editing or creating child posts. I just realized how confusing this is - in my opinion it should not be possible to create a Relationship Form and select a one-to-many relationship. I have reported this to my 2nd tier support team as a Usability issue. In the meantime, please review the documentation here that describes how to manage One-to-Many relationships using a child post Form: https://toolset.com/documentation/post-relationships/selecting-parent-posts-using-forms-create-child-items/

You can use the Create Child Post link to create a new Example post related to the current Harmful Strategy, or you can show a View of Example Posts and include an Edit Post link next to each one. Clicking the Edit Post link will lead the User to an Edit Post Form, where they can manage the parent / child relationship link.

#916743

Hi Christian, many thanks for investigating and following up. I agree that the whole thing is rather confusing. I hope that in future versions of Toolset, it will become possible to select child posts when using a form to create a parent post (as indicated on the page you referred to). And it would also be really helpful if the same could be enabled with many-to-many relationships. Anyway, thanks for helping out, have a great weekend!