Skip Navigation

[Resolved] Many to Many relationship with post type and user/author, alternative method?

This support ticket is created 6 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 3 replies, has 2 voices.

Last updated by Christian Cox 6 years, 11 months ago.

Assisted by: Christian Cox.

Author
Posts
#521113
only admins available to author client posts.JPG
access control for investor user role.JPG

Hi again,
I spent a couple of hours reading articles, support threads and tutorials on this thing.

I have a post type "Projects", these are pages with information about Oil projects in Texas and Louisiana, and then I have the WordPress users, these are the investors.

I need to connect projects and investors, so that I can display "my projects/investments:" on the client page, to provide quick links, to view the projects they're currently investing in.

I'm here:
I created a post type called "client", because it doesn't seem possible to create any relationship between WordPress users and posts, only between posts, so "Client" should act as the user.
Then I created "client projects" to be an intermediary, to connect "clients" and "projects".

"Client projects" has parents "Projects" and "client". And it seems to be working, that one "client" have multiple "projects".
But my system doesn't know who the "client" post types belong to, so it's useless knowing what projects it has.

The easiest way to know what "client" post is what "WordPress user", would be if the user was the author of the client post, right?

But I have tried different settings with access control, to make this user role able to author "Client" post type, but I am only able to select the administrators to author the posts.

See images

Thanks for your time,
Best regards
Lykke

#521176

Hi, would a repeating field approach work? You could add a repeating Number field to a User Field group. Then you could add the project ID of each project they belong to.

Alternatively, you could add a repeating Number field to each Project, and include the User ID of each related user for each project.

#524036

Hi, thanks for your reply 🙂

I've tried this but I think I'm a little confused how to display the right projects to the logged in user.

I have the "wordpress user", the "Client" post type and the "project" post type.
WordPress users has a custom number field with the "client" post type ID. The purpose is to make a client post equal to a wp user.

The "client" post type is connected to the projects through an intermediary.

I think I made a mess, what do you think?

Is it really not possible to use access control to make other user roles authors of a custom post type?
Is it only admins that can be authors of custom post types?

Thank you for your time,
Lykke

#524042

The approach I was thinking about does not use intermediaries. Create a custom field in your project post type called "Project Users". This field is a repeating number field. Add each associated User ID in a repeated field. This works well if you have few users and many projects.

Project 1
- User 1 ID
- User 2 ID
- User 3 ID

Project 2
- User 2 ID
- User 4 ID
- User 5 ID

Project 3
- User 1 ID
- User 4 ID

...and so on. The main drawback to this approach is you need to know each user's numeric ID in order to associate them with a project.

Another approach: create a custom User field called "User Projects". This field is a set of checkboxes, where each checkbox represents a single project. Then you can check off any projects the user belongs to.
User 1
- Checkbox for Project 1 (checked)
- Checkbox for Project 2
- Checkbox for Project 3 (checked)

User 2
- Checkbox for Project 1
- Checkbox for Project 2 (checked)
- Checkbox for Project 3 (checked)

User 3
- Checkbox for Project 1
- Checkbox for Project 2 (checked)
- Checkbox for Project 3 (checked)

...and so on. Whenever a new project is added, you must update your custom field options (in one single place) to include the new checkbox for all users. Then you could go into each User's profile and check off the new project to grant them access.

Is it really not possible to use access control to make other user roles authors of a custom post type? Is it only admins that can be authors of custom post types?

Sure, it is possible for Access to grant other user roles publish and various other permissions for a custom post type. Go to Toolset > Access Control > Post Types. Open the custom post type and check "Managed by Access". Check "Publish" next to the user role you want to allow publish rights for your custom post type, and check any other permission you want that user role to have. Most likely "Edit own" "Preview own" and "Read" should be checked.

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