Title: wpdb::tables
Published: April 25, 2014
Last modified: February 24, 2026

---

# wpdb::tables( string $scope, bool $prefix = true, int $blog_id ): string[]

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wpdb/tables/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/classes/wpdb/tables/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wpdb/tables/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wpdb/tables/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wpdb/tables/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wpdb/tables/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/classes/wpdb/tables/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/classes/wpdb/tables/?output_format=md#wp--skip-link--target)

Returns an array of WordPress tables.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wpdb/tables/?output_format=md#description)󠁿

Also allows for the `CUSTOM_USER_TABLE` and `CUSTOM_USER_META_TABLE` to override
the WordPress users and usermeta tables that would otherwise be determined by the
prefix.

The `$scope` argument can take one of the following:

 * ‘all’ – returns ‘all’ and ‘global’ tables. No old tables are returned.
 * ‘blog’ – returns the blog-level tables for the queried blog.
 * ‘global’ – returns the global tables for the installation, returning multisite
   tables only on multisite.
 * ‘ms_global’ – returns the multisite global tables, regardless if current installation
   is multisite.
 * ‘old’ – returns tables which are deprecated.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wpdb/tables/?output_format=md#parameters)󠁿

 `$scope`stringoptional

Possible values include `'all'`, `'global'`, `'ms_global'`, `'blog'`, or `'old'`
tables. Default `'all'`.

`$prefix`booloptional

Whether to include table prefixes. If blog prefix is requested, then the custom 
users and usermeta tables will be mapped.

Default:`true`

`$blog_id`intoptional

The blog_id to prefix. Used only when prefix is requested.
 Defaults to `wpdb::$
blogid`.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wpdb/tables/?output_format=md#return)󠁿

 string[] Table names. When a prefix is requested, the key is the unprefixed table
name.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wpdb/tables/?output_format=md#source)󠁿

    ```php
    public function tables( $scope = 'all', $prefix = true, $blog_id = 0 ) {
    	switch ( $scope ) {
    		case 'all':
    			$tables = array_merge( $this->global_tables, $this->tables );
    			if ( is_multisite() ) {
    				$tables = array_merge( $tables, $this->ms_global_tables );
    			}
    			break;
    		case 'blog':
    			$tables = $this->tables;
    			break;
    		case 'global':
    			$tables = $this->global_tables;
    			if ( is_multisite() ) {
    				$tables = array_merge( $tables, $this->ms_global_tables );
    			}
    			break;
    		case 'ms_global':
    			$tables = $this->ms_global_tables;
    			break;
    		case 'old':
    			$tables = $this->old_tables;
    			if ( is_multisite() ) {
    				$tables = array_merge( $tables, $this->old_ms_global_tables );
    			}
    			break;
    		default:
    			return array();
    	}

    	if ( $prefix ) {
    		if ( ! $blog_id ) {
    			$blog_id = $this->blogid;
    		}
    		$blog_prefix   = $this->get_blog_prefix( $blog_id );
    		$base_prefix   = $this->base_prefix;
    		$global_tables = array_merge( $this->global_tables, $this->ms_global_tables );
    		foreach ( $tables as $k => $table ) {
    			if ( in_array( $table, $global_tables, true ) ) {
    				$tables[ $table ] = $base_prefix . $table;
    			} else {
    				$tables[ $table ] = $blog_prefix . $table;
    			}
    			unset( $tables[ $k ] );
    		}

    		if ( isset( $tables['users'] ) && defined( 'CUSTOM_USER_TABLE' ) ) {
    			$tables['users'] = CUSTOM_USER_TABLE;
    		}

    		if ( isset( $tables['usermeta'] ) && defined( 'CUSTOM_USER_META_TABLE' ) ) {
    			$tables['usermeta'] = CUSTOM_USER_META_TABLE;
    		}
    	}

    	return $tables;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wpdb.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/class-wpdb.php#L1128)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/class-wpdb.php#L1128-L1184)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wpdb/tables/?output_format=md#related)󠁿

| Uses | Description | 
| [wpdb::get_blog_prefix()](https://developer.wordpress.org/reference/classes/wpdb/get_blog_prefix/)`wp-includes/class-wpdb.php` |

Gets blog prefix.

  | 
| [is_multisite()](https://developer.wordpress.org/reference/functions/is_multisite/)`wp-includes/load.php` |

Determines whether Multisite is enabled.

  |

| Used by | Description | 
| [wp_uninitialize_site()](https://developer.wordpress.org/reference/functions/wp_uninitialize_site/)`wp-includes/ms-site.php` |

Runs the uninitialization routine for a given site.

  | 
| [upgrade_network()](https://developer.wordpress.org/reference/functions/upgrade_network/)`wp-admin/includes/upgrade.php` |

Executes network-level upgrade routines.

  | 
| [dbDelta()](https://developer.wordpress.org/reference/functions/dbdelta/)`wp-admin/includes/upgrade.php` |

Modifies the database based on specified SQL statements.

  | 
| [is_blog_installed()](https://developer.wordpress.org/reference/functions/is_blog_installed/)`wp-includes/functions.php` |

Determines whether WordPress is already installed.

  | 
| [wp_version_check()](https://developer.wordpress.org/reference/functions/wp_version_check/)`wp-includes/update.php` |

Checks WordPress version against the newest version.

  | 
| [ms_not_installed()](https://developer.wordpress.org/reference/functions/ms_not_installed/)`wp-includes/ms-load.php` |

Displays a failure message.

  | 
| [wpdb::set_prefix()](https://developer.wordpress.org/reference/classes/wpdb/set_prefix/)`wp-includes/class-wpdb.php` |

Sets the table prefix for the WordPress tables.

  | 
| [wpdb::set_blog_id()](https://developer.wordpress.org/reference/classes/wpdb/set_blog_id/)`wp-includes/class-wpdb.php` |

Sets blog ID.

  |

[Show 3 more](https://developer.wordpress.org/reference/classes/wpdb/tables/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wpdb/tables/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wpdb/tables/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.1.0](https://developer.wordpress.org/reference/since/6.1.0/) | `old` now includes deprecated multisite global tables only on multisite. | 
| [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/classes/wpdb/tables/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/classes/wpdb/tables/?output_format=md#comment-content-3669)
 2.   [Gianluca Raftacco](https://profiles.wordpress.org/gianrftcc/)  [  6 years ago  ](https://developer.wordpress.org/reference/classes/wpdb/tables/#comment-3669)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwpdb%2Ftables%2F%23comment-3669)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwpdb%2Ftables%2F%23comment-3669)
 4. To list all [wpdb](https://developer.wordpress.org/reference/classes/wpdb/) tables:
 5.     ```php
        global $wpdb;
        print_r($wpdb->tables);
        ```
    
 6.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwpdb%2Ftables%2F%3Freplytocom%3D3669%23feedback-editor-3669)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwpdb%2Ftables%2F)
before being able to contribute a note or feedback.