Skip Navigation

[Resolved] User Edit Many to Many Relationships

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 9 replies, has 2 voices.

Last updated by Minesh 8 months ago.

Assisted by: Minesh.

Author
Posts
#2686109

Ian

I have a site with a post type of "vendors". This is in a many to many relationship with a post type "affiliations" that allows vendors to show any associations they belong to. Only an admin or manager can add new posts to affiliations.

The vendor listing shows these affiliations in a view example attached as affiliations.jpg

Vendors are able to edit their listing with front end forms. I have created a form that allows vendors to connect to new affiliations. Shown in add affiliation.jpeg

What I have not been able to figure out is how to allow vendors to disconnect affiliations. The documentation around this appears to be non existent. Also the help in the technical support area is not particularly clear and quite old.

Is there a way I can let vendors disconnect the affiliations in the many-to-many relationship.

#2686151

Ian
affiliations.jpeg
add affiliation.jpeg

Forgot the images

#2686240

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

To delete a post-relationship, you can use the Toolset Forms shortcode [cred-delete-relationship] inside the loop of the view, that shows the related posts:

More info:
- https://toolset.com/documentation/programmer-reference/forms/cred-shortcodes/#cred-delete-relationship

Example:

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

Where:
- Please replace the 'relationship-slug' with the actual slug of the relationship.

Does that helps?

#2686538

Ian
related posts.jpeg

I have created a view to show the custom post (vendors) from the currently logged in user. This view works properly.

Inside that view I have a nested view that shows the related posts. This view is displaying the related posts properly. Here is the code for that view:

[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
<div style="margin-bottom: 1em;padding-bottom: .5em; border-bottom: 1px solid #999999"><p class="nma">[wpv-post-title]</p>
[wpv-post-featured-image size="medium"]
[cred-delete-relationship role_items='$fromViews' relationship='affiliation-vendor' redirect='self']Disconnect[/cred-delete-relationship]
</div>
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No affiliations found[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]

I am not getting the option to disconnect the relationships.

#2686631

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Using what user role you logged in on frontend?

Can you please share problem URL where you added the view and admin access details.

Please share frontend user access details as well.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2687280

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

It seems the issue here is its a many-to-many post relationship.

So, for instance, the following "Affiliations " post has two related post if you check the "post relationship" box:
- hidden link

Still with the view you shared - you are displaying "Affiliations" and we do not know what related post you want to delete.

Do you want to display only "Affiliations" posts whose author is loggedin user?

Or

I think we can list all related vendors attached to single Affiliations post and check if that help.

#2687310

Ian
relationships.png

The view in question hidden link shows Affiliations for the loggedin user and their Listing page. So the view is showing one of the many-to-many relationships. This is the listing hidden link that matches with the vendor login I gave you.

The listing is currently showing only those affiliations that go with the vendor listing. So I am getting the right affiliations showing I just can not delete the relationship. This view is intended only to be shown to vendors I will be hiding it from "market managers".

#2687462

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

There is some strange thing happening and I could not able to make the disconnect link working.

Can you please send me duplicator copy of your site.
- https://toolset.com/faq/provide-supporters-copy-site/

I have set the next reply to private which means only you and I have access to it.

#2687865

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Thank you for sharing the site copy. I've escalated the issue in front of our next level support. Please hold on for further updates.

#2688089

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now:
- hidden link

When you use[cred-delete-relationship] shortcode to disconnect the posts - to check whether users have permission to disconnect posts is not based on delete posts permissions, but on edit post permissions for both posts, on the left and right of the relationship.
And the way those permissions work, you need publish rights to be allowed including edit rights.

On the access control page:
- hidden link

For the Vendor role - I've grant the published capabilities for both post types in relationship that is: Vendors and Affiliations

I can see the Disconnect link now with above page when I added the following shortcode to the following view:
- hidden link

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

Here is the errata:
- https://toolset.com/errata/setting-the-edit-any-post-permission-using-toolset-access-doesnt-allow-editing-published-posts/

#2688153

Ian

Minesh, that is working great. Thanks for the help and the information, I have a few more relationships to take care of setting up forms for.