Skip Navigation

[Resolved] Restrict relationship form to author of page

This support ticket is created 5 years 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 5 replies, has 2 voices.

Last updated by Stina 4 years, 12 months ago.

Assisted by: Luo Yang.

Author
Posts
#1394035

I have a site with two post types; guides and methods. Guides can add methods to there profile post with a relationship form on the post with their profile. I have restricted the form to logged-in users with access code based on role. But I want each guide to be able to only add methods to their own profile, not to others. So I need to limit the form by author of the page. How do I do that?

Thank You!
Stina

#1394069
author.JPG

Hello,

I assume we are talking this case:
Two post types: guides and methods
one-to-many relationship between post types guides and methods

There is a post form for creating new "methods" post.

In above post form there is a parent "guides" selector, you are going to limit the options of parent "guides" selector as:
"guides" posts, which author is current logged-in user.

If it is, it is possible with Toolset form, please try this:

Edit the post form for creating new "methods" post, find and edit the parent "guides" selector field, there is an option "Get only options by the current author", see screenshot author.jpg

If you are using expert mode, you can add the attribute author='$current' in that shortcode, for example:

[cred_field ... author='$current']

More help:
https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_field
author Optional. Use it with a parent selector field to specify that the list of parent posts should be limited to those authored by the mentioned user ID. The value $current can be used to define that the current user should only see their own parent posts in a dropdown.

#1394081

Hi,
I've already done that, you can only add methods, the name of the guide is set by the post. Now any logged-in guide can add methods to any guide, by going to the post with that guide's profile. I need restriction by the author, so you only can add methods to the page you are the author of. I need to hide the form from everyone else. So when you go to your profile post you see the form, on others not. Is it possible?

#1394099

Sorry, it is a many to many relationships.

There is a form to add methods, a form to add guides, and a form to relate them.
Anyone who is logged in can add any amount of methods, without adding them to any other post.
A member can create one profile post.
On their profile post, they can add any amount of methods to their profile, using the relationship form.
The relationship form should only be visible if you are the author of the post. You are not supposed to add methods to others profile posts.

I tried to change:
[toolset_access role="Administrator,Editor,Author,Contributor" operator="allow"][wpv-post-body view_template="add-method-to-current-practitioner-templats"][/toolset_access]

to
[toolset_access author='$current' operator="allow"][wpv-post-body view_template="add-method-to-current-practitioner-templats"][/toolset_access]

but then I couldn't see the form on my post.

#1394101

You can use [wpv-conditional] shortcode to check if the logged-in user is current page author, then display the post form, for example:

[wpv-conditional if="( '[wpv-current-user info="ID"]' eq '[wpv-post-author format="meta" meta="ID"]' ) "]
current user is same as the post author of current post, display the post form
[/wpv-conditional]

More help:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-author
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-user

#1397285

My issue is resolved now. Thank you!