Skip Navigation

[Resolved] 3 different types relationship and views based on one of them Dep – Name – Role

This support ticket is created 8 years, 1 month 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 15 replies, has 3 voices.

Last updated by Shane 8 years ago.

Assisted by: Shane.

Author
Posts
#375381

Hi,
I have tried to set up an relation between 3 types but I cannot see how I could do it.
I have the following entities, posts
Department
Person
Department role

A person can belong to many Departments
A person can have many role within a Department
A Department can have many roles
A role can only belong to one Department

Example:

Department: It-support
Person: Johan
Role: Database, Server

Department: It-support
Person: Kalle
Role Database

Department: It-support
Person: Anna
Role : server, storage

Department: Accounting
Person: Johan
Role: Payrolls

Department: Accounting
Person: Anders
Role: Analyst

The display I would like to have is

IT Support
Johan Kalle Anna
Database, Database Servers
Server Storage

Accounting
Johan Anders
Payrolls Analyst

How should I create the relationships and how should I put the views together that’s my question?
I know that I should use intermediary objects. I know how to do it if I take Department away. But now adding a third entity I don’t know. And with 3 entities I cannot really understand how to build the views. I can do it with 2 but with 3 I have no clue.
BR
Johan

#375560

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Johan,

Thank you for contacting our support forum.

Might I suggest using a taxonomy instead? To me this issue sounds more like taxonomy related than a custom post type issue.

For example you can create the taxonomies, department and role then in each taxonomy you can add the roles and departments.

Finally you are able to add multiple roles and departments to each employee simply by selecting the taxonomy term that they belong to.

Let me know your thoughts of this.

Thanks,
Shane

#376541

Hi,
Sounds like a good and easier plan to do to use taxonomies. So I have now created one taxonomy called Department and one taxonomy called roles and populated it to the persons. In this scenario I dont see how we can set the relationship between departments and roles so I can build views reflecting each department with persons and their department roles.

If I use only on taxonomy I can set the departments as parents and the roles as children, However, in this case I haven't figure it out how to build views.
Please help me which taxonomy to use and how to set up the views.

BR
Johan

#376555

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Johan,

So the way i'm thinking about this is that the relationship for Department and Roles to be imaginary, this means that the Roles taxonomy will have all the roles available and not limited by department.

All you need to do is to select the role and department that applies to that person.

Then all you need to do to display this information is to create a view that lists all the employees and format it with this shortcode.

Department: [wpv-post-taxonomy type="department" separator=", " show="name" order="asc"]
[wpv-post-name]
Role: [wpv-post-taxonomy type="role" separator=", " format="link" show="name" order="asc"]

This should list out your items in the correct format.

Please let me know if this helps.

Thanks,
Shane

#376778
deprartment-view.png
person-view.JPG

Hi,
Thats a good start but your view is not how I would like to display it, img, person-view. I would like it to be sorted on departments, img deprartment-view.
BR
Johan

#376795

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Johan,

I'm getting a image of what you are trying to do.

Is it that on 1 employee will belong to 1 department?

Because i'm looking at a setup that will require multiple views. 1 view to list the department and another view list employees and their roles.

For example we have a similar setup to the one in our documentation below.
https://toolset.com/documentation/user-guides/using-a-child-view-in-a-taxonomy-view-layout/

Please let me know if this helps.

Thanks,
Shane

#378119

Hi,
This is how the setup is:
A employee can belong to many Departments
A employee can have many roles within a Department
A Department can have many roles
A role can only belong to one Department
BR
Johan

#378170

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Johan,

Would it be possible for me to gain access to your website so I can setup a short demo for you to show you how to set this up?

The private fields will be enabled for your next response.

Thanks,
Shane

#380220

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Johan,

Thank you for the credentials, but it seems that it does not have admin privileges.

Could you upgrade it to an admin account and let me know.

Thanks,
Shane

#380227

I'm struggling with this same issue and have run into problems with Taxonomy. The organization of database records you describe indicates several different many-to-many relationships. Although Taxonomy supports this, the issues come up when you try to build views without duplicate records.

Taxonomies provide a comma-separated list of terms assigned to posts. If you have people assigned to multiple roles and also multiple departments, it's difficult, if not impossible to easily display either a list of departments the user is assigned to, and under each, the roles they have in each department. Conversely, it's as difficult to display a list of roles to which a user is assigned and, under each role, the department in which they perform that role.

You'll need to find each instance where the taxonomy terms match between users, departments, and roles. That means creating some custom code that can accept the list of taxonomy terms assigned to each post, and match those to the terms assigned to each child post - assuming your posts are organized that way.

Although it means more nesting of views, I've found it more versatile to create Custom Post Types (CPTs) to link between each many-to-many relationship.

You would have:
People
People-to-Department links
Department
Department-to-Role links
Role

If you need it, you can also have People-to-Role links.

The linking post types have no editor, title, or admin menu. All they do is store the post ID of the 2 posts they relate. The linking post types are configured to be children of the 2 post types they link.

Then, you search Roles, for example. For each found role, you search the linking db for each child of the current Role. For each found record, you search for all the parent posts in Department to display all of the related departments.

I've needed to use a pen and paper to sketch the structure of each view, as it gets really, really confusing without a lot of practice, but, this approach provides the most robust structure. You can change People, Roles and Departments at any time and the database stays organized.

When editing any CPT, the related links interface is available, which makes managing the data on the backend relatively straightforward - not particularly fast, but intuitive.

The other significant problem is that Users is not treated like a standard CPT in WP-Types. That means that standard WP users are not as easy to integrate into views of other CPTs. That's probably for security reasons, but, I don't think it's a necessary restriction.

I like to use the WP-Users type whenever possible because it provides all of the lost password functionality, email notification and session management stuff that would otherwise have to be built by hand.

What I do to make this all work with users is to create a "Pseudo-User" CPT. There are one of these Pseudo-User records for each WordPress user, and the WP user is the author of their own, individual Pseudo-User post. Now, I can use the Pseudo-User CPT in my views just like any other CPT, and I can access user information, like email, display name, etc., but displaying the author post-meta within the Views editor.

I have requested that WP-Types incorporate this functionality into Views. A checkbox in the settings should just enable this pseudo-post-type, and just maintain one post for each WP user, but keep the pseudo-type completely hidden. Just provide easier access to user info within the Views editor.

Until then, this work around does make things work, but can be time consuming to set up if you have lots of users initially.

I'll keep watching this post to see if you have success using Taxonomy, otherwise, feel free to keep in touch and I'll help you as I can. It seems that I can more clearly understand what I'm working on if I try to explain it to others in a similar situation.

#380656

Hi
The account is now admin
sorry!

#380740

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Johan,

Take a look a this page.
hidden link

Also these are the views used 🙂
hidden link

hidden link

Please let me know if this helps.
Thanks,
Shane

#381397

Hi,
Thats a good start. But how do we show roles that only belongs to each the Department. LIke IT Department with the Roles Database, Software Developer,
HR: Manager
Finace: accounting
?

#381399

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Johan,

Great, so what you are saying is that there are Roles that are specific to departments correct?

In this case you will need to not use a general Role taxonomy but in fact create a deparment role taxonomy that holds the roles specific to that department.

Because the roles that are being displayed currently are determined by the user and not the department they are attached to.

Please let me know if this explanation was clear.

Thanks,
Shane

#381401

You are correct about the roles!
So I need to put both roles and employes in Department taxonomies. Ok, I try it out thanks!
/Johan

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