Skip to content

Instantly share code, notes, and snippets.

@devuri
Last active May 22, 2021 00:20
Show Gist options
  • Save devuri/cc896dc664f53c29d265c01c9dd6eca6 to your computer and use it in GitHub Desktop.
Save devuri/cc896dc664f53c29d265c01c9dd6eca6 to your computer and use it in GitHub Desktop.
How to Retrieve a list of database table names for WordPress Database
<?php
namespace MyPlugin\Database;
class WPTable
{
/**
* Get wp database tables.
*
* @return object
*/
protected static function tables() {
global $wpdb;
return $wpdb->get_results(
$wpdb->prepare( "SHOW TABLES" )
);
}
/**
* Get the tables list.
*
* @return array .
*/
public static function table_list() {
foreach ( self::tables() as $get_tables ) {
foreach ( $get_tables as $table ) {
$list[] = $table;
}
}
return $list;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment