Problem: I have a many-to-many (M2M) post relationship between two custom post types. I would like to be able to manage the custom fields applied to the relationship and also delete relationships from the front-end of the site using Forms.
Solution:
Create a Relationship Form to manage this M2M relationship.
Since there are some limitations with the Block Editor, the next step is to create an unassigned Content Template and choose to use the classic editor (link at the bottom of screenshot 1-classic-editor.png) to edit the template.
Then use the Forms button above the editor to insert the Relationship Form, and choose to create an "editing mode" template in the Form popup (2-editing-mode.png). Insert the shortcode and you'll see a shortcode appear in the template, like so:
[cred-relationship-form form='ranks-and-chapters']
Now you have an editing mode template for editing this relationship. In the loop of the View of related LCA Databases posts, you need to insert a Relationship Link to edit this relationship. The limitation here is it's not possible to generate this link from Blocks. Instead, you can use this shortcode as a template. Edit the code as described below and insert in a paragraph block:
[cred-relationship-form-link form='ranks-and-chapters' role_items='$fromViews' content_template_slug='ranks-chapters-editing-mode']Edit this CustInt[/cred-relationship-form-link]
Replace ranks-and-chapters with the slug of your Relationship Form. Replace ranks-chapters-editing-mode with the slug of the editing mode Content Template you just created. Replace Edit this CustInt with the text you want to display for the link.
Save the Tools Content Template and visit the Umberto Tool post on the front-end of the site. Now in the View of related LCA Databases you should see a new link to edit the relationship. Click the link to see the Edit Relationship Form, where you can manage the custom fields associated with this relationship.
To delete the relationship, use the Forms shortcode in the loop of the View of related posts:
[cred-delete-relationship role_items='$fromViews' relationship='relationship-slug' redirect='self']Disconnect[/cred-delete-relationship]
This will create a "Disconnect" link that will allow your Users to disconnect the M2M relationship from the front-end of the site.
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 18 replies, has 2 voices.
Last updated by 3 years, 9 months ago.
Assisted by: Christian Cox.