Skip Navigation

[Resolved] Front-End Editing and Deleting of Post Relationships

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

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 support ticket is created 3 years, 2 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 philipS-3 3 years, 2 months ago.

Assisted by: Christian Cox.

Author
Posts
#1931813

Okay I see, you're referring to a checkboxes group field applied to the intermediary post type. There is an open issue about this specific field type in Post Relationship Forms: https://toolset.com/errata/custom-checkboxes-fields-are-not-saved-in-post-relationship-forms/

Unfortunately I don't have a good workaround available right now for this specific field type, but individual checkbox fields are working as expected so you might be able to implement a series of individual checkboxes instead, depending on the site requirements. I've asked my team leader to find out more about the status of this issue.

#1933027

Okay, no worries, for now I'm just testing capabilities so either I change the custom field type or I check back, when I want to go live, what the status of that bug is.

Now, final question - I hope 😉 How can I make the buttons you set up now - for editing the connection and for disconnecting so that they just appear for the post author? I tried to do it via a condition that specifies the author ID of the post to be same, which works fine for adding databases because that's outside of the view. But because the other buttons are in the view, the condition can only be set for the database or post relationship author ID - which is not what I want. Any ideas how to make this still work?

Kind regards, Philip

#1933401

Sure, you can use a conditional that tests the post author ID from the current post being displayed (the Tool post) and compares it to the current logged-in User ID. The format for that conditional in shortcode form looks like this:

 [wpv-conditional if="( '[wpv-post-author item="$current_page" format="meta" meta="ID"]' eq '[wpv-user field="ID"]' )"]
...place the disconnect button shortcode here...
[/wpv-conditional]

Let me know if you have problems with this, and I can take a closer look.

#1933659

Thanks a lot! I really appreciate all your help in figuring this out 🙂

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.