A brief article demonstrating how to populate a select field with a callback function using Meta Box.
I am in the middle of a project to create a new event management system. One of the requirements is to relate events to participating staff; those staff members will have a different role depending on the event. While the relationship part is fairly straightforward (Events and Participants are CPTs), the role solution eluded me for a while. After asking in the Facebook group, my solution is to create a cloneable group with the staff member’s name and a role drop-down. I didn’t want to duplicate information but to use the participant information I already had (CPT).
The Query
Being fairly inexperienced with writing WordPress queries (I am trying), I turned to ChatGPT, gave it a prompt, and in a matter of seconds it gave me a usable query complete with comments.
PHPfunction custom_get_speakers()
I have some additional testing to complete to make sure the values are what I need. Once the testing is done, I will finalize the single template and publish another article to outline the entire process.
Dynamic Select
Once you have a query available, adding it to the select is just a matter of adding the function name. I opted to use the Advanced Select because, eventually, this list will have 40-50 entries, and I wanted it to be searchable.


Leave a Reply