Skip Navigation

[Resolved] Populate a select field in a form, with available users from WordPress.

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

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by Pierre 2 years, 6 months ago.

Assisted by: Waqar.

Author
Posts
#2194817
work-shift-form-and-list.png

I'm want to build a simple form for a secure (intranet-like) site where the employees should be able to change their working shifts.
Basically, anyone who has logged in should be able to visit a page called "Change work-shift" and on that page, they should see a list of already made "posts" of work-shift changes.

A logged-in employee should be able to add the following using a form:

Job date
Shift type: Morning, Afternoon, Night
Change from: Username/employee
Change to: Username/employee

What is the best way to solve this? I'm thinking...
-A custom post type called "Work shift"
-Custom fields for that CPT
-Then a new page to show a view with already created work-shifts + the form to add more
???

#2195511

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting us and I'd be happy to assist.

You're thinking on the right lines and you can add a custom post type "Work shift" and then attach the necessary custom fields to this post type.

For fields "Change from" and "Change to", you can add two select type custom fields. The options for these fields can be programmatically generated from the list of WordPress users, using the "wpt_field_options" filter:
https://toolset.com/documentation/programmer-reference/types-api-filters/#wpt_field_options

You'll find a relevant code for a similar requirement, in this reply:
https://toolset.com/forums/topic/creating-my-own-custom-field-types-2/#post-1707651

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2198157

Thank you Waqar,
Good to know I'm on the right track.
Unfortunately, I'm not a coder. I'm more of a designer with some basic coding skills.

I looked at the relevant code you suggested but that still looks a bit like greek to me.

Can you please assist me with the correct code snippet for my problem?

Thanks!

#2199767

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for writing back.

The code snippet from the other ticket is ready-to-use for your requirement too. You'll only need to replace "Book User" with the select type field name used on your website and the "subscriber" role, with the target role of users, you'd like to include in the list.

For more personalized assistance around custom code, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

#2201421

Thank you!
I managed to reuse the code snippet you referred to.

My issue is resolved now. Thanks!

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