Chosen Multi Dropdown with populated data
-
I’m using your chosen multi drop down and thought I’d move the issue to the forum.
Here’s my full code…
/** * Plugin Name: Participants Database - Populate Custom 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 */ 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 first_name,last_name,job_category,record_slug FROM <code>' . $wpdb->prefix . 'participants_database</code> WHERE job_category NOT LIKE "%staff%" '; // 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 ) { if ($record->job_category == 'faculty') : $options[] = $record->first_name.' '.$record->last_name.' (Faculty)'; elseif ($record->job_category == 'staff') : $options[] = $record->first_name.' '.$record->last_name.' (Staff)'; elseif ($record->job_category == 'researcher') : $options[] = $record->first_name.' '.$record->last_name.' (Researcher)'; elseif ($record->job_category == 'student') : $options[] = $record->first_name.' '.$record->last_name.' (Graduate Student)'; endif; } // now set the field object with the new options list $field->options = $options; endif; }
Now, to reiterate my issue, it is inputting my data in fine but when I save my changes and go back to the drop down, it is merging my choices into one
- tag. Please help and thank you!
The page I need help with: [log in to see the link]
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Chosen Multi Dropdown with populated data’ is closed to new replies.