Skip Navigation

[Resolved] Link user list to custom post type

This support ticket is created 4 years, 10 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 13 replies, has 2 voices.

Last updated by Luo Yang 4 years, 10 months ago.

Assisted by: Luo Yang.

Author
Posts
#1280737

Here is a little intro to what I am doing : I have a website for my association and I have some of the members writing. I want to display all the members. Only the writers/admin have a account on the website. For the people writing, I want to link their user on the custom post type "Members" I created so I can display their content on the single-members template.

#1280745

Hello,

I think it is possible within Toolset, for example, you can try these:
1) Create a custom post type "Member", each "Member" post author is different WordPress user, one writers/admin can have only one "Member" post

2) Create a parent user view:
- query WordPress users:
- in section "Content Selection", enable option: Any role
- in section "Loop Editor", within Views loop, display below child post view

3) Child post view:
- Query "Member" posts
- Filter by:
Select posts with the author the same as the current logged in user.
- and display "Member" post link

More help:
Filtering Views Query by Author
https://toolset.com/documentation/user-guides/filtering-views-query-by-author/

#1280757

Thank you for the fast answer.

I am not using the views, I use Toolset only to creates and manages de posts. The display is done with PHP only.

I think I misexplained my situation.

I created a custom post type "members".

I have 50 members in the association. 3 people are administrators on the website, 10 are writers.

I need to display the 50 members on the website within the "archives-members.php" template.

Everyone will have a public profil on the "single-members.php" template. For the 10 writers, on this template, I want to display their content (posts).

I am looking for the easiest way to insert the user id/link the user profil to the correct member so I can query their content.

#1280789

Same as I mentioned above, you just need the step 1) and step 3).

1) Make sure each "Member" post's author is different WordPress user, one writers/admin can have only one "Member" post

2) In "archives-members.php" template, within the loop, setup custom PHP codes:
- Query "Member" posts
- Filter by:
Select posts with the author the same as the current logged in user.
https://codex.wordpress.org/Class_Reference/WP_Query#Author_Parameters
- and display "Member" post link
https://developer.wordpress.org/reference/functions/get_post_permalink/

And if you are using Views plugin, then it does not need custom PHP codes.

For your reference.

#1280913

But with your Step 1), it include that every writer will create his member post, I don't really want to allow them to do anything with theses posts.

Only admin should be able to do that

#1281445

In your case, it is required to setup a connection between post type "Member" and WordPress users (writers/admin).

You can control the post author settings as an administrator, for example:
Dashboard-> Toolset-> Post Types, find and edit post type "Member":
In section "Sections to display when editing ", enable option "Author"

So when you edit a "Member" post, you will be able to change the post author to specific wordpress user.

#1281583

Oh, I understand now.

I didn't think that way, it's so simple like this. I'll try this and come back if needed.

But for the future, on another project or post type, how could I achieve what I was asking first ?

How to get a custom field listing all the WP user inside a custom post type's admin page ?

I tried with a one-to-one relationship but I can't select the User post type, something I am missing ?

#1281591

For other new post types, for example "my-cpt-1", you can setup one-to-one relationship between post types "Member" and "my-cpt-1".

So in a single "my-cpt-1" post, you can display the "Member" post information by above relationship:
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-one-related-item-parent

You don't need to input the "Member" information again, just need to display the existed "Member" post information.

#1281677

Ok so I was following your solution with the Author but I came across something.

While building the template, I started to query the posts by author. It's good for the writers, but not the others.

As an exemple, if an author with content create a member, the last one isn't a writer, it will display his content.

#1281735

You can check that user is an author user, then run the child post query.
If it isn't, then don't run child post query.

Since you are using custom PHP codes to setup the query, I have searched it in google, and found this thread:
https://wordpress.stackexchange.com/questions/5047/how-to-check-if-a-user-is-in-a-specific-role/5048#answer-54837

for your reference

#1281767

Thought about the same thing but the problem is the same.

One role by user, so if I create the member, it will not display my posts on his page, neither on mine.

Until I figure out how to display a user list in the post's admin, I will use the author solution combined with a "is a writer" boolean.

#1282469

For the new problem:
One role by user, so if I create the member, it will not display my posts on his page, neither on mine.

Please elaborate the question with more details:
How do you setup the user roles?
How do you create the member?
How do you display posts on his page? which one is his page?

Please provide detail steps to duplicate the same problem, thanks

#1283279

I use Oasis Workflow for my editorial workflow and Toolset as my CPT-manager. All the templates are made from scratch in our homemade theme.

The members are created from the dashboard by an administrator.

Users can be :
- Writer
- Corrector
- Publisher
- Admin

A role has all the power of the ranks above his. Admin have publisher, corrector, writer rights and more, publisher have corector, writer and more,...

Members is a CPT created to display all the members of the organisation even if they are NOT users of the website.

On my single-member.php template, I want to display, if the member also wrote some posts, everything he did.

We write 2 types of content : Posts and News. Same thing, just a different workflow.

#1283627

You can try these:
- setup one-to-many relationship between post types "member" and "posts",
https://toolset.com/documentation/post-relationships/
- Edit each post, setup it's parent "member" post
- In single-member.php template, you can setup PHP codes to query related "posts", see our document:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/#wp_query-argument-for-querying-by-related-posts

There is an example codes in section "NEW APPROACH" of above document.

For your reference.

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