Skip to content

Instantly share code, notes, and snippets.

@kodie
Created April 23, 2021 18:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kodie/bd1ca18b73a131805d357d21bccaaeee to your computer and use it in GitHub Desktop.
Save kodie/bd1ca18b73a131805d357d21bccaaeee to your computer and use it in GitHub Desktop.
Use a datalist in place of a select dropdown for wp_dropdown_users in WordPress
<?php
// Use a datalist in place of a select dropdown for wp_dropdown_users
add_filter('wp_dropdown_users', 'wp_dropdown_users_datalist');
function wp_dropdown_users_datalist($html) {
preg_match("/name='(.*?)'/", $html, $name);
preg_match("/id='(.*?)'/", $html, $id);
$html = str_replace(array('<select', '/select>'), array('<datalist', '/datalist>'), $html);
$html = preg_replace("/id='$id[1]'/", "id='$id[1]-list'", $html);
$html = preg_replace("/name='$name[1]'/", '', $html);
$html = "<input list='$id[1]-list' id='$id[1]' name='$name[1]' />\n" . $html;
return $html;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment