I'm building a prototype of a membership site that will work thus: an admin can upload a PDF document (custom post type) and make it available to a customer (individual user). The only users that should see that document are the admin and the customer in question. The admin can do other functions (such as create/add a customer). There are multiple types of documents (controlled by a custom taxonomy). To keep things simple, I'd prefer to do this from the front-end but will happily do use the back-end if needs be.
My issue is with the relationship between the customer and the document. Is it sufficient to rely upon the Author field and assign the document to the customer by 'changing' the author? I could then generate a view based upon the Post Author for the customer to see their documents. Or is there a way to create/add a user and assign it to a document using a CPT? I'm at a bit of a loss.
Hello,
I suggest you try with custom CPT workaround, for example:
1) Create a custom post type "customer", setup each "customer" post author as a individual wordpress user, one user can have only one "customer" post.
2) Create post type relationship between "customer" and "PDF document"
- if one user can view multiple "PDF document" posts, and one "PDF document" post can be viewed by multiple users, you can use many-to-many relationship
- if one user can view multiple "PDF document" posts, and one "PDF document" post can be viewed by only one user, you can use one-to-many relationship
https://toolset.com/documentation/post-relationships/
3) Create a page as customer dashboard page, in this page create a post view, query "customer" posts, filter by:
Post author is the same as the logged in user
In view's loop, display below child view:
4) Child post view, query "PDF document" posts, filter by the post type relationship(step 2), and display the PDF file link
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-many-related-items
Thanks ever so much for the reply. Correct me if I'm wrong, but wouldn't this mean that I would have to create each WordPress user individually and then assign it as an author to the CPT "Customer"?
I suppose what I'm trying to do is combine the two and 'automate' the process, ie. create a WordPress user and CPT in one process.
Yes, it needs to create each WordPress user individually and then assign it as an author to the CPT "Customer", and you can setup a post form let your user to create the new "Customer" post, see our document:
https://toolset.com/documentation/post-relationships/how-to-create-custom-searches-and-relationships-for-users/#how-do-i-prevent-users-from-creating-more-than-one-contractor-post