I am using a function that works for one dropdown menu on a form for Team. I need to have it do two more dropdown menus for Organization and Country similarly based on inputs from the database. How do I make it do the function 2 more times where the $fieldname = organization and $fieldname = country? Thanks for your help!
add_action( 'pdbcde-before_element_rendered', 'xnau_set_specialty_dropdown_options');
/**
* sets the options for the "specialty" dropdown
*
* @global wpdb $wpdb
* @param PDb_FormElement object $field the current field
*/
function xnau_set_specialty_dropdown_options ( $field )
{
// this is the name of the field we want to add options to
$fieldname = 'team';
if ( $field->name === $fieldname ) : // check for our dropdown field
global $wpdb; // grab the db helper object
/*
* define the query for getting the list saved specialties
*
* 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 DISTINCT `' . $fieldname . '`
FROM ' . $wpdb->prefix . 'participants_database
';
// 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 = $field->options;
foreach ( $raw_names as $record ) {
// this is the value we'll be considering
$new_value = $record->{$fieldname};
/*
* check the value against the defined options so we only
* add options that are not already in there
*/
if ( ! in_array( $new_value, $options ) ) {
// it's a new value, so add it to the dropdown options
$options[$new_value] = $new_value;
}
}
// now set the field object with the new options list
$field->options = $options;
endif;
}