Skip Navigation

[Resolved] Filter loop by Access Groups where user belongs

This support ticket is created 6 years, 10 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
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by Martín Mellado 6 years, 10 months ago.

Assisted by: Noman.

Author
Posts
#538798

Hey guys,

I am trying to:

Build a project management tool, where the single view of the CPT "Project" show everything segmented by 2 variables: user role and some access condition.

In the single view i accomplished everything i wanted so in this part i'm ok. What i've accomplished so far:

1- The single page of a project show different informations depending on the user role.
2- When a user tries to enter to a project where it doesn't belong it can't enter and is redirected to another page.

The challenge i'm trying to solve right now is that i want to have more than 1 user assigned to every single project, so i want to restrict the single page to a company, and then assign users to that company.

The access problem i solved it with "Access Groups", using them as every single company, deleting all user roles and assigning specific users to the access group. The solution works fine for the single page (if the user doesn't belong to the group is redirected to an specific template), but not to loop through all the projects, because each client can see every project in the platform.

Without this solve i can't achieve my clients to have their own profile and be able to see only their specific projects as a list, and to have more than 1 user per project (so assigning the project to an author is not a solution).

I expected to see:

A list where the user see only the projects that are correlated to the roles where the user belongs.

I need a way to create a filter that can display only the projects where the user have access to read. In that way i can simply use Access Groups as Companies to restrict access, and filter the inside contents with user roles. This would be a perfect solution for the platform, because it could be super flexible to even identify an user by more than 1 user role.

Instead, I got:

[Wrong] A list of every single project [Here i need a filter that Views doesn't have]
[Ok] Access control to more than one user per post.
[Ok] Segmented content by user role

Thank you very much for your time

#539074

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Martin,

Thank you for contacting Toolset support.

Access plugin does not work on View Loop items, this thing would need custom code to make it work. For the other things, I am not sure how your Companies are added to display on the site or how they are currently displaying their profile pages. but I would imagine or suggest following steps in this case and there are two suggested methods and you can use anyone which is suitable to your setup:

Method 1:
By adding Companies as “Taxonomies”. Using the steps mentioned here:
https://toolset.com/forums/topic/view-to-show-sub-cateogories-of-parent-set-by-shortcode/#post-535627
==> Whereas you will create a “Post types” View for Projects, and the given code will need some modifications though.

Method 2:
1. Create 2 Custom Post Types using Types plugin = Company (Parent), Projects (Child)
2. Make parent child relationship between company and projects using Types.
3. Then use wpv_filter_query hook to create a custom function that will pass company_id as an attribute to the View’s shortcode:
-- https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

You can read more about Passing Arguments to Views shortcode here (Examples > Controlling the filter with shortcode attributes):
-- https://toolset.com/documentation/user-guides/passing-arguments-to-views/

4. And insert the shortcode in each company or its profile post. The resulting shortcode would be like:

 [wpv-view name="projects" company-id="1"] 

==> Whereas company-id will be different for each company in above shortcode.

Thank you

#539885

Hi Noman,

Thank your for your answer. I still don't have enough knowledge to modify php as it's required here, and giving it a second thought is not a great idea because i'm not using Toolset's strenghts. Right now, because of time i think both of the methods you are proposing are fine, but i will use a combination of the 2. I thought about it and i think creating a CPT for a user role is the best way to go because filtering will be easy (by author, or by many to many to display the company related to the role, projects, services, etc.). I just have to worry about the access to the taxonomy and is a lot more maintainable.

Thank you

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