Skip Navigation

[Resolved] Post Field to select user

This support ticket is created 6 years 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 1 reply, has 2 voices.

Last updated by Luo Yang 6 years ago.

Assisted by: Luo Yang.

Author
Posts
#1183145

I would like to add a field to one of my custom post types which would allow me to select a user so I can link that user to the post.

The background is that I have affiliates in my system. The affiliates have normal wordpress users and the custom post type has some information about the project of the users. I now need a way to build a relationship between the user and his posts so when a visitor comes via an affiliate link to the page, I can use the affiliates ID to retrieve information about him form the posts of the custom post type.

A plain textfield storing the affiliate ID would do it for me but since the site is for a customer who I do this project for will need to make the conenction between affiliates and their projects and for them it would be a lot easier to select the affiliate by name instead of going to the users page, finding the user, looking up the ID and entering the ID in the field on the post page.

Is this somehow possible? I was first thinking about the Toolset Relationships but since users are not a post type, they don't show up in the list. Is it possible to extend the types which are available in the custom fields section and implement my own dropdown which shows users?

#1183368

Hello,

You are right:
since users are not a post type, they don't show up in the list

There are two options you can choose:
Option 1) Create a custom select field, use "wpt_field_options" filter hook to populate the select field options, see similar thread:
https://toolset.com/forums/topic/dropdown-that-shows-all-users/#post-590063

Option 2) Setup another custom post type "affiliates", setup each "affiliates" post's author as different affiliate user, then use post type "affiliates" to setup relationships with other post types, see our document:
https://toolset.com/documentation/post-relationships/how-to-create-custom-searches-and-relationships-for-users/