Skip Navigation

[Resolved] Create a relationship with Users and Custom post type.

This thread is resolved. Here is a description of the problem and solution.

Problem:

I am creating a portal for different counties where each county will have several different users. Each user in that county should be able to view invoices(post type) created by any user within that county. Other county users should not be able to view other counties invoices(post type). To do that i have one custom post type that has all the counties in the database. To which i can attach to individual users and invoices(post type). 4 - 5 users will have same counties thru out the database.

Solution:

There isn't exact same feature within Toolset plugins, as a workaround, please check the details here:

https://toolset.com/forums/topic/create-a-relationship-with-users-and-custom-post-type/#post-1125218

Relevant Documentation:

https://toolset.com/documentation/user-guides/passing-arguments-to-views/#accessing-the-arguments

This support ticket is created 6 years, 3 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/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 6 years, 3 months ago.

Assisted by: Luo Yang.

Author
Posts
#1124880

I am trying to:
I am creating a portal for different counties where each county will have several different users. Each user in that county should be able to view invoices(post type) created by any user within that county. Other county users should not be able to view other counties invoices(post type). To do that i have one custom post type that has all the counties in the database. To which i can attach to individual users and invoices(post type). 4 - 5 users will have same counties thru out the database.

In ACF, i know there is a custom field that references post object to specific user. I want to create a relationship or have a field in user table where i can set county(custom post type) of that specific user. In the views i want to be able to show all invoices(post type) that fall in that specific counties. Every user that is associated to that county should be able to view the invoice (post type) attached to that county.

#1125218

Hello,

There isn't exact same feature within Toolset plugins, as a workaround, you can consider these:
1) Create a custom user select field "Country"
https://toolset.com/documentation/user-guides/user-fields/

Then each user can setup his Country in his profile page, or you can setup a user form for editing current user, users can also use this form to update the "Country" field value
https://toolset.com/documentation/getting-started-with-toolset/publish-content-from-the-front-end/forms-for-editing/

2) Create a custom post select field "Country", register to post type "invoices"
https://toolset.com/documentation/user-guides/using-custom-fields/
use same options as the user field

3) In the front-end, you can get the user field "Country" value by using Types shortcode
https://toolset.com/documentation/user-guides/displaying-wordpress-user-fields/
pass it to below post view as shortcode attribute "user-country"

4) Create a post view, query "invoices" posts, filter by post field "Country" is same as views shortcode attribute "user-country":
https://toolset.com/documentation/user-guides/passing-arguments-to-views/#accessing-the-arguments

For your reference.

#1125518

Thank you so much for your support! I will try this solution and get back to this post to let you know how it went.

#1125772

You are welcome