Skip Navigation

[Resolved] Problem is that I cannot display employee’s functions next to the children group

This support ticket is created 7 years, 11 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

Author
Posts
#399031

I am trying to: display employee’s functions next to the children group where they are being displayed

I visited this URL: hidden link

I expected to see: display employee’s functions next to the employee in children group

Instead, I got: that is not working / it says "no data", or it's empty

Hello. I am building a website for the kinder garden with WP Toolset. The goal is to make a system fully adaptable to customer needs and them being able to manage everything on the go. I made three custom post types that are related to each other in many-to-many relationships:

Employee (Full name, education, etc.)

Functions (teacher, assistant teacher, etc.)

Children groups (group 1, group 2, etc.)

1st and 2nd groups are related through a connectible post type called “Employment”, that is their parent group.

1st and 3rd groups are related through a connectible post type called “Education”, that is their parent group.

When I make a View “Employees table” I have no problems fetching employee’s functions and displaying them on a table with id tag (view “Employees”, Employee Name [wpv-post-title], Employee Functions [view functions for employee], which fetches their functions using ID tag from Employment).

The same goes with success when displaying children groups with currently connected employees (view “Children groups”, Group title [wpv-post-title], Employee working with children [view employees for children group”]).

Now the problem is that I cannot display employee’s functions next to the employee in children group where they are being displayed. For example, there is the view list that displays all children groups, next to them connected employees, and next to them should be their function, like that:

Children group “Stoneheads”

Employees:

John Doe (teacher)

Alla Doe (assistant teacher)

Children group “Quickies”

Employees

John Doe (teacher)

Stew Doe (assistant teacher)

Bam Doe (coordinator)

Please help as this is very important project that we are gonna be implementing for many governmental institutions in our country!

#399153

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

First, a quick question.

Is there a particular reason why you have added an employee's function (John Doe is a teacher) by creating the Employee CPT and Function CPT as children of a parent Employment CPT?

A simpler solution would be to make your Employee CPT and add a custom field with the employee's role (probably via a select box to restrict what can be added to pre-defined roles). That would make displaying the role alongside the Employee name relatively trivial using the [wpv-post-field] shortcode.

https://toolset.com/documentation/views-shortcodes/#wpv-post-field

If you have already considered and dismissed this option let me know and I will think through the alternative you have proposed.

#399167

Hello Nigel, thanks for your quick reply.
Yes i have did that in my first attempt and that worked well, but this option limits end-user's ability to add needed roles. Thing is, that all government institutions have universal requirements for their web - sites (info, structure) written in law, but they all have their employee's roles and in most cases they are different, especially in different type of institution (let's say not kinder garden, but hospital, etc). WP-Types lets to do everything else needed for such a product, and only this hard question about connecting these together remains after several days of thinking and experimenting...

#399203

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Shame!

Well, the next question is, do you still need the intermediary Employment CPT?

The relation between Groups and Employees is many-to-many, hence the requirement for the Education CPT intermediary.

But the relationship between your Functions and Employees is one-to-many. You don't need the intermediary in that case, you could make your Employee CPT a direct child of your Function CPT.

So Alla Doe and Stew Doe would both be children of the function "Assistant teacher".

That would reduce the complexity of your Views. Is that an option, or shall I keep thinking?

#399500

I have got rid of many-to-many relationships for Employee-Functions. Functions now is parent post type of Employee.

Q1. When displaying employees data table, in a place where employee functions should be displayed, I get the same text as employee's name, since he is not assigned any functions. How to use conditional output to show, e.g. "not yet employed" or just to show blank space?

Q2. When displaying a single item of Functions, I need to see all of the employees listed below, so I can easily see, who are employed for such functions.

E.g.

list of Functions:

Teacher
Assistant Teacher
Coordinator

On a single post of Functions I need to have:

title, description...
<...>

Employed for this position:

John Doe
Sarah Doe
Bam Doe

... (all of the employees belonging to that Function).

#399505

Here is screenshot, which may help to understand everything
hidden link

#399751

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Screen Shot 2016-05-19 at 09.18.07.png

OK, after a lot of head-scratching I have it working as you can see in the attached screenshot. I only created the template for looking at a single Group but I think you know how to do the same for displaying your list of Groups.

I couldn't retrieve the Function of the Employee in the set-up as we currently had it. I followed the steps for many-to-many relationships as described here:
https://toolset.com/documentation/user-guides/many-to-many-post-relationship/

But I connected Groups AND Employees AND Function with a single intermediary object (which I called Assignment, e.g. John Doe is assigned to work as a teacher in the Stoneheads group).

So Assignment is a child of each of the 3 custom post types.

Now when I build my Assignment View (as described in the docs), but adding an id to the shortcode I can switch which parent I am accessing for the content.

That allowed me to add this to my Loop output (directly, you might use a content template):

<wpv-loop>
	<h3>[wpv-post-title id="$employee"], [wpv-post-title id="$function"]</h3>
</wpv-loop>

There is a side effect, which I'm going to call a benefit, in that it now allows you to say that, for example, John Doe works as a teacher at Stoneheads, but as a coordinator at Quickies.

#399824

No, that is not exactly how this needs to work.. Here i will try to show full scheme, which i need to achieve.

Here is full scheme screenshot
hidden link

Views needed:
List of Employees + their Function
List of Children groups + Emploeeys + his Function
List of Functions + Employees belonging to that function
List of Work groups + Employees + Role in work group

#399871

I have managed to show Work Groups with Employees and their Role in the group. That was done using may-to-many (MTM) relationship. Parent “Group assignment”, child “Employee”, “Role”.

This does not apply to Children groups, because Employee can only have one Function and be an Educator of several Children groups, but his function does not change in there. So “Function” should be parent of “Employee” in a single-to-many (STM) relationship form. “Education” is parent of “Employee” and “Children group” in MTM way.

#399893

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

assignment_hierarchy.jpg
hierarchies.jpg

I've created a simple diagram to illustrate how the parent-child relationships affect the Views that you can create which should help you decide how to structure your data. See the attached screenshot hierarchies.jpg

In the first image, CPTs 'A' and 'C' share an intermediary child 'B' and 'C' and 'E' share another intermediary child 'D'.

That means you can use B to create a View with content from A & C, or you can use D to create a View with content from C and E, but you cannot access content from both A and E in the same View.

In my last post I highlighted the solution shown in the second image, where CPTs 'A', 'C', and 'E' each share a common intermediary child 'B'. Now, using B, you can construct a View with any content from any of A, C, and E.

There also exists the possibility to access content from grandparent posts, as described here:
https://toolset.com/documentation/user-guides/displaying-fields-grandparents/

That means that you also have the option of something like the last image in my screenshot, where there is common intermediary 'F'. Construction a View using F will give you access to the content from any of A, B, C, D or E.

Now in that example, B, D and F are intermediaries created purely to connect A, C and E.

In your case, I think—think—that if you organise your data as per the second screenshot you should be able to create each of the Views you require.

#399904

Your solution has worked. I made a View, that selects: Assignment with Query Filter: Select posts that are a children of the current post in the loop.

Instead of having [wpv-post-link id="$employee"] in a loop and not being able to access its parent (function) I have put a content template there [wpv-post-body view_template="test" id="$employee"] and the content template looks like this: [wpv-post-title], [wpv-post-title id="$function"].

Now everything works. We appreciate your help very much!!!

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