Last active
May 3, 2023 08:03
-
-
Save ahmu83/358f8e41e6134013991d9e3cf5edaf8c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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