I'd like to know how can I approach this better and what are my options. I cannot use AJAX requests for this.
I have a dropdown select populated through a SELECT
query from the Database. The dropdown displays the user's display_name as the label and their IDs as the value. So:
$('select').val()
retrieves an ID.
My problem is I'd like to display the selected user's username (another column from the same database table) in the onchange event of the Dropdown select.
Am I approaching this incorrectly?
EDIT:
I'm usiing Advanced Custom Functions for Wordpress, so this is how I'm retrieving my select and populating it:
function acf_load_color_field_choices( $field ) {
$field['choices'] = array();
foreach ($query as $row) {
$field['choices'][$row[ID]] = $row[display_name];
}
return $field;
}
add_filter('acf/load_field/name=select_name', 'acf_load_color_field_choices');
Any idea if there's a way to add a data- attribute to this?