I am working on a wordpress meta box that will have repeatable dropdown fields made up of a list of users from the site that is queried from the database. I am having trouble getting the array to output in the manner that is outlined on this github.
Here is my current code:
<?php
global $wpdb;
$users = $wpdb->get_col( "SELECT display_name FROM {$wpdb->prefix}users WHERE ID !=1 ORDER BY display_name ASC" );
foreach ( $users as $user ) {
echo '<option value="'.$user.'">'.$user.'</option>';
}
?>
The current output looks like so:
<option value="User Name">User Name</option>
I need the output to look like this:
$options = array (
'Option 1' => 'option1',
'Option 2' => 'option2',
'Option 3' => 'option3',
'Option 4' => 'option4',
);
return $options;
The way that the dropdown is generated is as follows:
<select name="select[]">
<?php foreach ( $options as $label => $value ) : ?>
<option value="<?php echo $value; ?>"<?php selected( $field['select'], $value ); ?>><?php echo $label; ?></option>
<?php endforeach; ?>
</select>