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.

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
#1928671

Hey guys,

first of all, Toolset is amazing! I bought it few days ago and I am truly amazed by its functionality, but also by the support that's provided through the videos, courses etc. - well done!

I've set up custom post types, added edit forms, linked different cpts with one another, created custom directories etc. and everything works brilliantly. However, I've run into a few issues:

1) Despite having searched quite a bit for it, I haven't come across a support entry which explains to me in detail, how I can set up an "Edit" link to an entry with linked CPTs which then takes me to a form where a post relationship can be changed. I see the option which says "Create an "editing-mode" template...", but I don't fully understand how to do that and thus use it.

I found a support forum post to an entry here: https://toolset.com/documentation/post-relationships/how-to-build-front-end-forms-for-connecting-posts/editing-existing-connections-between-related-posts/#deleting-existing-connections-between-posts But the linked section is not existing anymore...

2) I've managed to create an "add post relationship" link - but unlike the "edit post" link, I fail to limit its access to the post author, as you can see here: hidden link So everyone could add a database - which is obviously not intended.

3) When I use the above mentioned form, it does save the post relationship to a new database - but the selected custom field value is not saved, as you can try yourself by selecting a value when saving the agri-footprint database.

4) Unlike the other post forms, the relationship form is a lot more limited, but it would be great to also have the ability to review relationships, before they are posted, which should be possible by setting the intermediary post to "pending". But I guess that's more of a future feature request.

Thanks a lot in advance in pointing me in the right direction 🙂

Kind regards, Philip

#1928679

Hi, it might be fastest if I could log in to your wp-admin area and see the types of post relationships you have set up, the post types involved, and the forms you're using to manage those relationships. Please use the private fields here to provide login credentials, and let me know a few details about each question:
1. Which post relationship are you trying to edit, and where would you like to display this 'edit' link? Please provide a URL.
2. If I can see this from the wp-admin side I might be able to suggest a way to limit access by post author using a conditional shortcode or conditional block.
3. I will take a look from the wp-admin side and see why this field might not be saved. Normally post relationship Forms do not edit custom fields in either post, only custom fields applied directly to the relationship (i.e. the intermediary post type). I'll take a look and let you know what I find out.
4. Yes this would be more of a feature request, since there is no workflow available for reviewing relationship definitions or pending statuses for the relationship itself.

Private reply fields are available for your next reply in the forum.

#1928767

) Despite having searched quite a bit for it, I haven't come across a support entry which explains to me in detail, how I can set up an "Edit" link to an entry with linked CPTs which then takes me to a form where a post relationship can be changed. I see the option which says "Create an "editing-mode" template...", but I don't fully understand how to do that and thus use it.
Okay after reviewing your site I can see you're trying to edit an M2M relationship with Forms. There are some limitations for editing relationships in Forms when using the Block editor and the documentation isn't very clear, so let me put together some examples I can share with you to help guide you for setting this up the best way. My shift is ending today but I can follow up tomorrow with some additional information.

#1928769

Sorry I set the wrong status with my last message, I'm still working on this and will give you an update as soon as possible.

#1929393

Dear Christian,

thanks for your support. Now, as per your suggestion, I could use a condition for 2) to hide the "Add Database" and hopefully the coming "Edit Database" links. In my scenario most sense would make to say "show links if role = post author". But conditions seem to just check for the first role set, not the other roles a user might have. I encountered this issue already somewhere else and solved it by using this access short code [toolset_access role="role" operator="allow"] instead of the visual editor, which actually does check for multiple roles. So I could do this also in this case, but maybe there is a more elegant solution?

Also, please note that I am unable to include the link to the "Connect a Database Form" via the visual editor in the text and fields section. If I try to insert that block, it inserts "tinymce..." instead of the actual code. My workaround is to switch the editor to HTML and then add the code, which works fine. But as you can see in the content template for tools, the block itself then encounters an error in the backend. It works fine on the front-end, but you might want to look into why it's failing on the backend 🙂

Kind regards, Philip

#1929875
2-editing-mode.png
1-classic-editor.png

So I could do this also in this case, but maybe there is a more elegant solution?
I think your access shortcode solution is great, I would implement it the same way.

I haven't come across a support entry which explains to me in detail, how I can set up an "Edit" link to an entry with linked CPTs which then takes me to a form where a post relationship can be changed. I see the option which says "Create an "editing-mode" template...", but I don't fully understand how to do that and thus use it.
Since there are some limitations with the Block Editor, the first 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.

Let me know if you are able to see this, or if you get stuck, and I can offer some more guidance.

#1930017

Dear Christian,

thanks for your support. I tried to set it up exactly like you said, but I'm getting the following error: "The items in the conection are not well defined"

Not sure why, any ideas what I did wrong?

The unlinked content template has this short code:

[cred-relationship-form form="linking-databases-to-tools"]

The view template code looks like this:

[cred-relationship-form-link form='linking-databases-to-tools' role_items='$fromViews' content_template_slug='linking-databases-to-tools-editing-mode']Edit Database Connections[/cred-relationship-form-link] 

Kind regards, Philip

#1930153
Screen Shot 2021-02-02 at 1.23.20 PM.png
Screen Shot 2021-02-02 at 1.21.00 PM.png

The end goal here is that each LCA Database post in the View's loop will contain a link to edit the relationship between the Tool and that individual LCA Database post. Therefore, the cred-relationship-form-link shortcode should be inserted inside the loop to display an "Edit Database Connection" link with each LCA Database displayed in the loop. However, it looks like the cred-relationship-form-link shortcode is inserted outside the View's loop. You should move that shortcode into the loop.

You can move the editor above the loop if you'd like more space to design the results. Select the "View Loop" block and open the Loop Style panel to see an option to move the editor out of the grid. You can use the Block Navigation menu to quickly select the View Loop block. See the screenshots here for more information about this.

#1930197

Ok, I see what you mean. However, I moved the short code into the view and it's not showing anything on the front end. Neither if I put it in a paragraph, or as a short code block. Maybe you can set it up so it works and then I can have a look at it in terms of what you did differently 🙂

#1930205

Sure, let me take a quick look and give you an update shortly.

#1930243

Okay I made a few changes:
1. I enabled the Classic Editor Editing Experience here:
hidden link
2. I set the Content Template to use the Classic Editor here and inserted the Relationship Form:
hidden link
3. I adjusted the slugs of the Content Template in the shortcodes here:
hidden link

[cred-relationship-form-link form='linking-databases-to-tools' role_items='$fromViews' content_template_slug='tools-edit-linked-databases']Edit Database Connection[/cred-relationship-form-link]

Now I can see the Edit Database Connection links appear in the Tool post here:
hidden link

If I click the edit link for the GaBi database relationship, I am redirected here:
hidden link

I see the relationship form appear here, so I think the Edit Database Connection link is working correctly now. Can you confirm?

#1930369

Dear Christian,

Indeed, the form appears now and I can edit the custom fields for the relationship, which is great! However - at least on mobile in my current test - I cannot unlink the database?! Maybe I wasn’t clear in the beginning, but I want to be able to delete a relationship completely.

Kind regards, Philip

#1930457

Okay sure, the workflow for deleting the relationship is a bit different from editing the relationship. We have a shortcode available to create a delete relationship link, for example:

[cred-delete-relationship role_items='$fromViews' relationship='relationship-slug' redirect='self']Disconnect[/cred-delete-relationship]

However, I believe it only works in Views created in the legacy editor. I think there is a problem when implementing this shortcode in Views created in the Block Editor. Let me try a test in my local environment and confirm that, I'll give you an update when I can.

#1931505

No, I was mistaken, the shortcode works in this case. Here is the shortcode I placed in the View's loop:

[cred-delete-relationship role_items='$fromViews' relationship='tool-lca-database' redirect='self']Disconnect[/cred-delete-relationship]

I tested it once and disconnected one of the LCA Databases from the front-end. It seems to work as expected. The page reloads and now that LCA Database is no longer displayed in the View.

#1931581

Dear Christian,

brilliant, thanks a lot. Now the database can be disconnect, which is great! However, the issue of the custom field not being set remains for both cases, adding a new database as well as editing a connection. In neither case, the value of the custom field is stored in the intermediary item.

Kind regards, Philip

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