Skip Navigation

[Resolved] Filter a Relationship by author within a Form…

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

Problem:

How do I filter a relationship in a front end form, by the post author?

Solution:

It is possible within Toolset form, for example, you can try these:
Edit the "Return" Post Form, find and edit the "Product Registration" relationship field, there is an option, enable option "Get only options by the current author"

Relevant Documentation:

https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_field

This support ticket is created 5 years, 6 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
- 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 4 replies, has 2 voices.

Last updated by shawnW-3 5 years, 6 months ago.

Assisted by: Luo Yang.

Author
Posts
#1244809

Tell us what you are trying to do?
I have a form for users to submit product returns. I want the user to choose the product they will return from products they have registered. I built a CPT and Form for Product Registration. I used a relationship to connect the Product Registration to the CPT/Form for Returns.

It looks good, but, I need the user to only choose products they have registered. So, in short, how do I filter a relationship in a front end form, by the post author? I have thought through a few different things, like a view for instance, but I'm not sure I can filter a cred field, and a relationship field at that.

Is there any documentation that you are following?
Haven't found anything dealing with this.

#1244926

Hello,

Please elaborate the questions with detail steps:
How do you setup the post types and relationships?
How do you setup the "Product Registration"?
Where and how do you want to setup the relationship filter?

I need to test it in my localhost, thanks

#1245192
relationship.JPG
postform.JPG
formfrontend.JPG
cptbuild.JPG

I've added some images.

How do you setup the post types and relationships?
I made a custom post type for "Product Registration" and a custom post type for "Returns"...
I made a one-to-one relationship for "Product Registration" and "Returns" (see relationship.JPG)...
I made a Post Form for "Product Registration" and a Post Form for "Returns".

Scenario:
Customer X uses "Product Registration" Post Form on the front end to Register Products they own.
Customer X uses "Return" Post Form on the front end to Return Products they have Registered.

When Customer X is using the "Return" Post Form (see formfrontend.JPG) they are prompted to choose a post from the "Product Registration" relationship field.

Where and how do you want to setup the relationship filter?
Customer X should ONLY be able to select a post from the "Product Registration" relationship field that they created using the "Product Registration" Post Form.

The ISSUE is that they can choose "Product Registration" posts created by any user, ie Customer A, Customer B, etc.

In the "Return" Post Form I need to filter the relationship by Post Author. This way Customer X can only choose "Product Registration" posts created by Customer X.

#1245567
author-filter.JPG

It is possible within Toolset form, for example, you can try these:
Edit the "Return" Post Form, find and edit the "Product Registration" relationship field, there is an option, enable option "Get only options by the current author", see screenshot: author-filter.JPG

If you are using expert mode, you can add attribute author='$current' to form 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.

#1245985

Brilliant, can't believe I didn't think to check there! Thank you.