Hello, I am working on a site set up similar to this article: https://toolset.com/course-lesson/how-to-create-custom-searches-and-relationships-for-users/ . I have a group of Members (Contractors in your example) that I want to associate with an Institution CPT (Showcases in your example).
I have several of the forms successfully set up from the "Forms, Templates, and Views to create section". I also have the relation between the Member CPT And Institution CPT. A member can register and there's a page where I have forms to update the user information and the associated Member CPT which is working correctly.
I'm having problems with the connection from the Member CPT and the Institution CPT. I can create the forms to show the connection but they aren't working as expected.
On the page where I have my edit user form and edit Member CPT form, I've added a content template that has a view that supposed to add/edit the Member to Institution relationship. I'd like to have it where if there's not an intermediary post, show a form that lets you add the post. If there is an intermediary post, show a form that lets you change the Institution.
The Add intermediary form seems to work after following these instructions https://toolset.com/course-lesson/front-end-relationship-forms-for-connecting-posts/. I can see the intermediary post in the Dashboard. I'm having problems with the edit part. Do I need to create a new edit relationship form like with the Member CPT form? If I do, where do I put it so it can see the parent Member CPT and child Institution CPT?
I did find this post that is similar to what I want to do: https://toolset.com/forums/topic/edit-relationship/#post-2374307 however I couldn't make it work for my case. It looks like it links out to a separate page to manage the relationship. I'd like to keep all of the editable member options on the same page if possible.
I do have this set up on a development server so if you want to take a look at it there, I can share the login with you.
Thank you for your help!
Collin Condray
Hi Collin,
Thank you for contacting us and I'd be happy to assist.
Based on what you've shared, here are the elements that you'll need on the page to manage the relationships between the Member CPT and the Institution CPT:
1. There will be a form to create a new relationship connection between the Member CPT and the Institution CPT.
2. There will be a post view, that will show all the existing relationships between the current Member CPT and its related Institution CPT.
3. Inside that view's loop, you can include the "cred-delete-relationship" shortcode to delete the current relationship connection:
https://toolset.com/documentation/programmer-reference/forms/cred-shortcodes/#cred-delete-relationship
So, in short, there will be no 'editing of the existing relationships. A member will be able to either create a new connection or remove the existing one.
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar
Waqar,
I think this approach makes sense. I've got a view that shows another view with the add institution form if there's no member->institution intermediary post. When I use that view that contains the relationship form, I can create the intermediary post so I think we're good there.
If the view can find a member->institution intermediary post, I've got another view that supposed to show a remove relationship button. I've added the cred-delete-relationship shortcode there but I'm not seeing a link. I've added some fields above the shortcode to show the intermediary post id, title, etc. so that information is in the scope of the loop.
What should the syntax of the cred-delete-relationship short code be? I looked at the documentation and it says I need a relationship parameter with the current slug. Is that the slug of the relationship (member-institution-relationship) or the slug of the current post in the loop? If it's the second, how do I pass the current post slug to the shortcode parameter?
Please let me know if you need any more detail from me.
Thanks,
Collin
Thanks for writing back.
The 'relationship' attribute in the "cred-delete-relationship" shortcode accepts the slug of the relationship that needs to be deleted and not the current post's slug.
Can you please share temporary admin login details, along with the link to the page where this link is not showing?
I'll be in a better position to troubleshoot this and suggest the next steps, accordingly.
Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.
Thank you for sharing the access details.
I see that you've added the "cred-delete-relationship" shortcode in the view named "Remove Member Institution Form".
Since that view is showing the "{Company name} Members Institutions Intermediary Posts", you'll need to specify through the 'related_item_one' and the 'related_item_two' attributes, exactly which two posts should be disconnected.
Here is the example with the "wpv-post-id" shortcode and the item attribute to specify the parent and child posts to disconnect:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-post-id
https://toolset.com/documentation/user-guides/views-shortcodes/item-attribute/
[cred-delete-relationship type="button" relationship="{relationship-slug}" related_item_one="[wpv-post-id item='@{relationship-slug}.parent']" related_item_two="[wpv-post-id item='@{relationship-slug}.child']" redirect='self']Remove Institution[/cred-delete-relationship]
An alternative to the 'cred-delete-relationship' shortcode in the view for the intermediary posts, is the "cred-delete-post" shortcode:
https://toolset.com/documentation/programmer-reference/forms/cred-shortcodes/#cred-delete-post
[cred-delete-post type="button" action='delete' onsuccess='self']Remove Institution[/cred-delete-post]
When an intermediary post is 'deleted' (and not just trashed), it also results in deleting the associated relationship, in the background.
You'll see both links added to the view and you can keep the one based on your personal preference.
Waqar,
I think the cred-delete-relationship option is the more appropriate one for this use. However, the cred-delete-relationship shortcode only seems to work for me when I'm logged in as an admin. The cred-delete-post shortcode does works when I'm just a member but I'd like to make sure the other one works so I know the permissions are OK.
The member/institution intermediary post is there and I can show the institution name. I checked the access settings for the member/institution post type and the add and edit options are checked for the role the member has. I also have the delete own posts checked for this role as well. Is there another setting I need to update? Feel free to create your own member to check this out.
One other thing, in the view who's name ends in "Members Institutions Intermediary Posts", you've included a four letter acronym that could be used to identify my client. It's also in the short code example. Could you please remove that reference from the public reply and just make it a generic member reference?
Thanks,
Collin
Thanks for writing back.
I can't access the staging website that you shared earlier. Has it been moved to a different address?
For the Toolset Access permissions, please note that for “Edit Any” and “Edit Own” permissions to work, it is important that the "Publish" permission is also granted.
( background information is available at https://toolset.com/errata/setting-the-edit-any-post-permission-using-toolset-access-doesnt-allow-editing-published-posts/ )
Please make sure that the member user role has all these permissions for the post types, involved in the relationship.
As for the company's identifiable acronyms, they have been removed from my reply.
Waqar,
Thanks for hiding those initials. I was still able to login to the site with the credentials I shared with you this morning. I am developing locally and pushing my changes to the development server. You might just have caught it when the push was happening. Usually, it only takes a few minutes to make the push. If it happens again, can you wait a bit and try again and see if that was the issue? If not, I can do some more digging.
I gave the my member role publish permissions for all of the CPTs they might be able to use but that didn't seem to work. I also added the code that you linked to but that didn't change anything either. I also tried removing the member institution relationship and creating a new intermediary post but the cred-delete-relationship delete option still doesn't appear. The button does work when logged in as an admin.
Please let me know if I need to check anything else.
Thanks,
Collin
Thank you for sharing these details.
Looks like some GEO IP location restriction is involved and I had to change my location through a VPN, to access it.
For the "cred-delete-relationship" shortcode to work, it is important that the current user can edit and delete the post types involved in the target relationships.
When I checked the settings at WP Admin -> Toolset -> Access Control -> Post Types, none of your post types were being managed by the Access plugin. This means that your target user role "{Company Name} Member" (actual system name "s2Member Level 1") didn't have permission to edit or delete the two post types used in that relationship, i.e. '{Company Name} Members' and 'Institutions'.
From the same settings page, I enabled these two post types to be managed by the Access plugin and allowed this "s2Member Level 1" user role to publish, delete and edit these two post types and the link from the "cred-delete-relationship" shortcode is now showing for this user role too.
Waqar,
Glad that was a quick fix for the login information. I can get you whitelisted if you run into troubles in the future.
Your permission explanation makes sense and I see that remove relationship button now. Won't giving the members delete any/edit any permissions allow them to affect the submissions by other members? I can probably set up things so they can only see information for the logged in user but I'd like to make sure no on accidentally updates something they're not supposed to.
Would the cred-delete-post shortcode be a safer option that wouldn't require those permissions? Does that shortcode delete not only the post but the children associated with it?
Thanks,
Collin
Thanks for writing back.
If you're not comfortable granting additional permission to the users, then using the 'cred-delete-post' shortcode is definitely the safer option.
For every relationship connection/link, there is exactly 1 single intermediary post created. And, if a specific intermediary post is deleted, only that 1 single relevant relationship connection/link is removed. So, there shouldn't be any downside to using the 'cred-delete-post' shortcode to delete the target intermediary post, so that the relevant relationship connection is removed.
My issue is resolved now. Thank you!