Hi, I’m using Participant Database in WP, and it has a function that works great for one dropdown field. The problem is I need to call the function for 3 dropdown fields. Can I add this before the function?
If $fieldname = ‘team’, function xnau_set_specialty_dropdown_options ( $field );
If $fieldname = ‘organization’, function xnau_set_specialty_dropdown_options ( $field );
If $fieldname = ‘country’, function xnau_set_specialty_dropdown_options ( $field );
and get rid of this line to get what I want? Thanks!!
$fieldname = ‘team’;
The dropdown code that works is as follows>
<?php /** * Plugin Name: PDB Populate Chosen Dropdown * Description: tests loading a chosen element with options * * sets our function to be called when the pdbcde-before_element_rendered action * is triggered by the form just before the "Chosen Dropdown" is shown so we can * change the list of options to show */ // attach our function to the pdbcde-before_element_rendered action 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 */ ===> ADD MY 3 CALLS HERE? function xnau_set_specialty_dropdown_options ( $field ) { // this is the name of the field we want to add options to ===> GET RID OF THE FOLLOWING LINE? $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; }