Skip Navigation

[Resolved] Complex User-CPT relationship

This support ticket is created 7 years, 4 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)

Author
Posts
#466642

Hi,

I created another topic for a specific problem with CRED Form, but it's just one problem inside a larger challenge.

I'm working a website where registered Users with a specific role (Access) can add Woocommerce products, but "framed products" depending on their relationships to the CPT "Type of Product".

The process to create a product related with CRED form :
- the author can specify some infos (custom fields) and choose a Type of Product, but won't be able to choose a price, a title and a stock,
- depending on the Type of Product he selected, the CRED Form uses parent informations to set price and stock, and uses custom fields to set the title.

That's my first problem I'm currently solving on another post.

Here's the larger challenge :
- I would like to set, individually per author, who can choose which CPT Type of Product,
- so when the author is on the CRED form, he can only choose the Type of Product he's assigned to.

In other words, it's kind of a many-to-many relationship between Users and CPT in order to restrict the choice. I read it's not possible that way, but they're old posts, maybe it changed. If not, these posts aren't clear enough for me, that's why I created this one.

Example :
- Author 1 is assigned to Type of Product A, C and D,
- Author 2 is assigned to Type of Product A, B and C,
- as admin, I set who is assigned to what ; a Type of Product can have different author and an author can have several Type of Product,
- when Author 1 arrives on the CRED Form to create a Woocommerce Product, he can only choose between A, C and D (because I assigned him to those),
- let say he selected C. Then when he creates the product through the CRED form, the CRED Form uses parent's informations (Type of Product), which is C, to add the price and the stock,
√ then the page of Type of Product C displays fields from the CPT such as description, title, images, price, etc,
√ and with a View, it displays all the children (Woocommerce product) with title of the products, author profile picture, author name.

I gave the 2 last lines to explain what's the final result, but this part is marked √ because it's done. My problem currently is the Author sees all the Type of Product choices on the CRED Form and I don't know how to assign the CPT to the User.

Of course it would much easier to just let the author have the choice among all the Type of Products, but my goal is to restrict that.

I'm open to any idea ton achieve that goal, as long as I can easily "assign" the authors to several Type of Product, because I hope I'll have many authors and many Type of Product.

Thanks for your help.

#466840

Dear xavier,

How do you setup the field "CPT Type of Product"?
Is it a custom select field? Custom taxonomy? Or posts of custom post type?
If it is a custom post type? how do you setup the relationships between post type "CPT Type of Product" and "Product"?
Is the post type "CPT Type of Product" the parent post type of "Product"?
What kind of field type do you want to it to be displayed in the CRED form? a custom select field?
How do you setup the Author?
Is it wordpress users?
How do you setup the relationships between Author and "CPT Type of Product"?

I need details to duplicate same problem, test and debug it in my localhost, thanks

#466999

Hi Luo,

can I give you access to a test site with everything on it ? Just need a private reply.

The Type of Product (Tour on my test site) is a custom Post Type.

Post Type is parent of Product (Woocommerce).

I began with a few custom fields to understand how it works and then add more.

Author (guide on my example) is a wordpress user, a new role made with Access.

I've no idea of to bond that user role and my CPT...

#467269

OK, please duplicate same problem in a test site, and fill below private detail box with login details, I need test in a live website, thanks

#467689

Thanks for the details, I am checking in your website, will feedback if there is anything found

#467716

Thanks for the details, I can log into your website, could you point out the problem page URLs?
Where can I see the problem:
Author sees all the Type of Product choices on the CRED Form
And which one is the problem CRED form?

#467895

Hi Luo,

thanks for checking.

Sorry to say "Author", it was to explain a "general case". The role is "Guide". As you can see I've Guide A and Guide B.

For the CPT, I've Tour 1 and Tour 2.

Guide A and B can use the CRED Form (URL /events/) to create a Woocommerce product. They have first to choose the kind of tour (Tour 1 or 2) they want, because CPT Tour is the parent of Woocommerce product.

What I would like to achieve, is making kind of a many-to-many relationship between CPT Tour and User role Guide.

As admin, I would like to "check" Tour 1 and Tour 2 for Guide A, and Tour 2 for Guide B (example).

Then, when Guide A is on the CRED form, he can see and select Tour 1 and Tour 2. But Guide B can only see and select Tour 2.

I fear I can't make such many-to-many relationship between User and CPT like between CPT and CPT, but maybe there's a trick !?

#468109

Thanks for the details, there isn't such a feature within Types plugin which can setup many-to-many relation ships between wordpress user and custom post type
1) I suggest you setup another custom post type "Guides", each "Guide" post is correspond to an wordpress "Guide" user, then follow our document to setup the many-to-many relationships between post types "Guides" and "Tours"
https://toolset.com/documentation/user-guides/many-to-many-post-relationship/

2) In your CRED form, you can setup a generic select field "Tours", create custom PHP function to query "Tours" posts which is related to current user, and display them as the options. see our document:
https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_generic_field
Inside shortcode body the necessary options and default values are defined as JSON string (autogenerated by GUI).

#468246

Hi Luo,

thanks for your reply.

1) Are you going to support such feature in the future ?

How can I make "bond" each CPT Guide to its right User ?

2) When you say, "related to current user", do you mean the current user which has a User Role Guide or is a CPT Guide ?

I've 0 skills in PHP.

Does Toolset work on features to use their UI without writing any PHP for such requests ?

#468856

Q1) Are you going to support such feature in the future ?
As I mentioned above:
there isn't such a feature within Types plugin, if you agree, we can take it as a feature request, then I can forward it to our developers to evaluate it.

Q2) How can I make "bond" each CPT Guide to its right User ?
I assume you are talking about this:
"each "Guide" post is correspond to an wordpress "Guide" user"
It is wordpress built-in feature, you can edit the custom post type "Guide", in section "Sections to display when editing ", enable option "Author", then you should be able to see a dropdown menu for changing the post author.
More help:
https://codex.wordpress.org/Function_Reference/register_post_type#supports

Q3) When you say, "related to current user", do you mean the current user which has a User Role Guide or is a CPT Guide ?
The current user means the user who is logged into your website, similar to the wordpress function get_current_user_id
https://developer.wordpress.org/reference/functions/get_current_user_id/

Q4) Does Toolset work on features to use their UI without writing any PHP for such requests ?
As I mentioned above: there isn't such a feature within Toolset plugins
It needs custom PHP codes, according to our support policy, we do not provide custom code support:
https://toolset.com/toolset-support-policy/
I suggest you check out our certified partners:
https://toolset.com/consultant/

#469033

Q1) Yes ! It would be awesome.

Q2) I don't see any dropdown menu when I enable Author.

Q3) Well you talked first about "related to current user" and I asked first what do you mean about this.

Q4) /

Q5) (New) I think I'm going to use the Events Calendar. They have "organizer" which seems to be a CPT. How can I use Toolset to edit a CPT created by another plugin ?

#469170
2305.JPG

Q2) When you edit/create a new post, click button "Screen Options", there is an option "Author", enable it, you will be able to see the meta box "author", see screenshot 2305.JPG

Q3) This is for your request: current user can only see the specific "Tours" posts in the dropdown menu of CRED form.
Then, when Guide A is on the CRED form, he can see and select Tour 1 and Tour 2. But Guide B can only see and select Tour 2.

Q5) Types can not edit CPT created by another plugin, but you convert other CPT and fields under Types control, see our document:
https://toolset.com/faq/how-do-i-convert-existing-custom-types-and-fields-to-types-control/
If you need more assistance for it please create new thread for the new questions. that will help other users to find the answers.

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