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?
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/