Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Plugin Name: PDB Volunteer Dropdown
- * Description: load the registered volunteers into a Participants Database form
- * dropdown
- */
- /*
- * sets our function to be called when the pdb-form_element_build_dropdown action
- * is triggered by the form
- */
- add_action( 'pdb-form_element_build_dropdown', 'xnau_set_volunteer_dropdown_options');
- /**
- * sets the options for the volunteer dropdown
- *
- * @param PDb_FormElement object $field the current field
- */
- function xnau_set_volunteer_dropdown_options ( $field )
- {
- if ( $field->name === 'volunteers' ) : // check for our dropdown field
- global $wpdb; // grab the db helper object
- /*
- * define the query for getting the list of volunteer names
- *
- * note that the $wpdb->prefix method is used to get the table
- * prefix; this is so it will work on all WP installs
- */
- $query = '
- SELECT first_name,last_name
- FROM `' . $wpdb->prefix . 'participants_database`
- WHERE form_type LIKE "%volunteer%" AND form_type NOT LIKE "%coordinator%"
- ';
- // now execute the query and get the results
- $raw_names = $wpdb->get_results( $query );
- /*
- * now expand the result array into an array for the options property of the
- * dropdown
- */
- $options = array();
- foreach ( $raw_names as $record ) {
- $options[] = $record->first_name . ' ' . $record->last_name;
- }
- // now set the field object with the new options list
- $field->options = $options;
- endif;
- }
Add Comment
Please, Sign In to add comment