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
???
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
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!
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/
Thank you!
I managed to reuse the code snippet you referred to.
My issue is resolved now. Thanks!