Skip to content

Instantly share code, notes, and snippets.

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 ahmu83/358f8e41e6134013991d9e3cf5edaf8c to your computer and use it in GitHub Desktop.
Save ahmu83/358f8e41e6134013991d9e3cf5edaf8c to your computer and use it in GitHub Desktop.
<?php
// This will break if the ENUM values have comma (,) in them
function get_enum_values($wpdb, $table, $field) {
$values = array();
$table = "{$wpdb->prefix}{$table}";
$query = "SHOW COLUMNS FROM {$table} WHERE Field = '{$field}'";
$results = $wpdb->get_results($query, ARRAY_A);
if (is_array($results) && count($results) > 0) {
preg_match("/^enum\(\'(.*)\'\)$/", $results[0]['Type'], $matches);
if (is_array($matches) && isset($matches[1])) {
$values = explode("','", $matches[1]);
}
}
return $values;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment