Skip Navigation

[Resolved] Conditionally display data based on grandparent

This support ticket is created 4 years, 5 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/Karachi (GMT+05:00)

This topic contains 5 replies, has 3 voices.

Last updated by Waqar 4 years, 5 months ago.

Assisted by: Waqar.

Author
Posts
#1668905

My custom post type is a Student. The parent post type is a School. The parent post type of a School is a District. I have user fields that identify the school and district that a user belongs to.

I have a really cool conditional View that shows Students that belong to the School of the logged-in user:

[wpv-conditional if="( '[types field='school-short-name' item='@school-and-student.parent'][/types]' eq '[types usermeta='user-school-name' current_user='true' output='raw'][/types]' )"]

I would like to now build a view that allows users to view Students that belong to the same district. Can you please advise?

#1669543

Hello,

Please elaborate the question with more details:
How do you setup user fields that identify district?
Is it a custom field to store the "district" post ID or post title?

#1671453

Hi Luo

I'm using Toolset User fields to identify the district.

At present, the Student post title is merely a concatenation of the Family Name and the First Name fields. The URL reads something like "cred-auto-draft-6876874862786427864784". I'm open to the idea of modifying either or both of these if it makes the solution easier?

#1673117

Hi Greig,

Thank you for sharing these details.

Luo will be on vacation this week, so I'll be following up on this ticket.

Based on what you've shared I understand that your custom post types are connected through the post-relationships already:

- Districts -> Schools (one-to-many)
- Schools -> Students (one-to-many)

If that is correct, the next point I would like to be clear on is what does a registered WordPress "User" represents in this scope?

a). Do you need specific users who will have access to these post type data based on associated/allowed schools and districts?
OR
b). Do you need each "Student" post linked to a registered user on the website?

regards,
Waqar

#1677147

Hello Waqar

You are correct on the relationships.

The WordPress users are assigned to a School. The users are responsible for adding and editing Student data for their school. For clarity, the humans here are the school administrators and school principals.

The schools are consolidated within districts and I now want to offer visibility of Student data across the district. In short, I want each user to have read-only access to data that belongs to their district. To illustrate:

District A comprises School 1 and School 2
District B comprises School 3 and School 4

I want users assigned to Schools 1 and 2 to be able to view each others' data but not that belonging to Schools 3 and 4.

There is no need for Students to be connected to users in any way.

Kind regards,
Greig

#1678235

Hi Greig,

Thank you for these details and that clears it further.

My recommendation would be to introduce a new custom post type "User Profiles" so that whenever you add a new WordPress user, you'll also add exactly 1 "User Profile" post where this new user is set as the post author.

This anchoring "User Profiles" post type will act as a user's reference for the associations with the other post types as "Users" can't be directly connected to post types through post-relationships. This approach will save you from storing user's connection with schools in user fields, which will become complicated to manage, once the data grows.

This same approach is also explained in this guide:
https://toolset.com/documentation/post-relationships/how-to-create-custom-searches-and-relationships-for-users/

The new post types and post-relationships structure will look like this:

- User Profiles -> Schools (one-to-many)
- Schools -> Students (one-to-many)
- Districts -> Schools (one-to-many)

You can easily get the current logged-in user's "User Profile" post through post author filter in a view.

Once, you have the correct "User Profile" post ID, you'll be able to get connected schools through post-relationship filter in a view.

And through schools, you can easily reach to related students or districts, as needed.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar