Good evening,
I tried to sort this out easily, but I did not get it around here.
I need my users to register with two actions going on.
1- The user writes the name of his "Company" (Creates new taxonomie).
2- The user writes the remaining information "Receive access" to read everything related to his "Company" (New taxonomy created).
Final result: The user registers a new taxonomy and receives access to view everything that is associated with it and only to it.
Dear reinaldo,
I assume the "Company" is a custom taxonomy.
You are going to achieve this:
When user submit the CRED form for creating user, add a new term in the "Company" taxonomy,
If it is:
1) There isn't user taxonomy, you can not assign a taxonomy to wordpress user, so there isn't such a built-in feature within CRED form.
2) You can try with some custom PHP codes, for example:
When user submit the CRED user form, use action hook "cred_save_data" to trigger a PHP function
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
In this PHP function, do this:
a) Create a post, set the post author as current user
https://codex.wordpress.org/Function_Reference/wp_insert_post
b) Assign above post with the specific taxonomy term
https://developer.wordpress.org/reference/functions/wp_set_object_terms/
For your reference.
I understand Luo Yang,
Unfortunately I still can not solve the problem, I will focus on the result to explain better.
I put an attached image, I need it:
1- A specific "Role" of users can only view or edit a content if it belongs to a specific company.
2- It must happen from the time of registration.
3- I need to associate these permissions in some way.
I assume the "Company" as a custom taxonomy.
Wordpress user's role is related with custom post types, it can not achieve what you want:
A specific "Role" of users can only view or edit a content if it belongs to a specific company.
https://toolset.com/documentation/user-guides/setting-access-control/
In your case, I suggest you try these:
1) You can create a custom post type, for example "user CPT", assign it with taxonomy "Company", each user will have only one "user CPT" post.
When user is created with CRED form, please check above answer to create the "user CPT" post:
https://toolset.com/forums/topic/user-registration-associated-with-your-company-taxonomies/#post-564119
2) When user is logged in, redirect him to a wordpress page, in this page setup a view to list "user CPT" post, whose author is current user:
https://toolset.com/documentation/user-guides/filtering-views-query-by-author/
Then you will get the "user CPT" post, and it's term of taxonomy "Company"
Use it to display the content related to this company.
Perfect Luo Yang, thank you for the support. I'm really understanding how the Toolset works.
You did exactly what you said, but I was not able to use the custom PHP code. I believe that is what is below.
- Insert post with custom taxonomy and post meta data (since 4.4.0):
$hierarchical_tax = array( 13, 10 ); // Array of tax ids.
$non_hierarchical_tax = 'tax name 1, tax name 2'; // Can use array of ids or string of tax names separated by commas
$post_arr = array(
'post_title' => 'Test post',
'post_content' => 'Test post content',
'post_status' => 'publish',
'post_author' => get_current_user_id(),
'tax_input' => array(
'hierarchical_tax' => $hierarchical_tax,
'non_hierarchical_tax' => $non_hierarchical_tax,
),
'meta_input' => array(
'test_meta_key' => 'value of test_meta_key',
),
);
1. I created the custom post type "user CPT", and assign it with taxonomy "Company".
2. I was unable to use the "CRED user form" to create a post, set the post to the current user and assign the post with the specific taxonomy term.
How exactly can I do this?
Result: I think of something similar to this hierarchy.
> Company
> Clients or employees
> Users
> Custom post
Each user can only see what is associated with his for him, by each company.
But each User is associated with more than one company.
Thanks for the help Luo.
We can handles the question one by one, for this question:
Q1) How exactly can I do this?
It is a custom PHP codes problem, if you need more assistance for it, please provide a test site with same problem, also point out the problem page URL and CRED form URL, and where I can edit your PHP codes, I need a live website to test and debug.
For other questions, please create new thread for each new question, that will help other users to find the answers. thanks