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

---

# wp_set_wpdb_vars()

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/wp_set_wpdb_vars/?output_format=md#description)
 * [Source](https://developer.wordpress.org/reference/functions/wp_set_wpdb_vars/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_set_wpdb_vars/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_set_wpdb_vars/?output_format=md#changelog)

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

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Sets the database table prefix and the format specifiers for database table columns.

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

Columns not listed here default to `%s`.

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

    ```php
    function wp_set_wpdb_vars() {
    	global $wpdb, $table_prefix;

    	if ( ! empty( $wpdb->error ) ) {
    		dead_db();
    	}

    	$wpdb->field_types = array(
    		'post_author'      => '%d',
    		'post_parent'      => '%d',
    		'menu_order'       => '%d',
    		'term_id'          => '%d',
    		'term_group'       => '%d',
    		'term_taxonomy_id' => '%d',
    		'parent'           => '%d',
    		'count'            => '%d',
    		'object_id'        => '%d',
    		'term_order'       => '%d',
    		'ID'               => '%d',
    		'comment_ID'       => '%d',
    		'comment_post_ID'  => '%d',
    		'comment_parent'   => '%d',
    		'user_id'          => '%d',
    		'link_id'          => '%d',
    		'link_owner'       => '%d',
    		'link_rating'      => '%d',
    		'option_id'        => '%d',
    		'blog_id'          => '%d',
    		'meta_id'          => '%d',
    		'post_id'          => '%d',
    		'user_status'      => '%d',
    		'umeta_id'         => '%d',
    		'comment_karma'    => '%d',
    		'comment_count'    => '%d',
    		// Multisite:
    		'active'           => '%d',
    		'cat_id'           => '%d',
    		'deleted'          => '%d',
    		'lang_id'          => '%d',
    		'mature'           => '%d',
    		'public'           => '%d',
    		'site_id'          => '%d',
    		'spam'             => '%d',
    	);

    	$prefix = $wpdb->set_prefix( $table_prefix );

    	if ( is_wp_error( $prefix ) ) {
    		wp_load_translations_early();
    		wp_die(
    			sprintf(
    				/* translators: 1: $table_prefix, 2: wp-config.php */
    				__( '<strong>Error:</strong> %1$s in %2$s can only contain numbers, letters, and underscores.' ),
    				'<code>$table_prefix</code>',
    				'<code>wp-config.php</code>'
    			)
    		);
    	}
    }
    ```

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

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

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

Attempts an early load of translations.

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

Loads custom DB error or display WordPress DB error.

  | 
| [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.

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

Retrieves the translation of $text.

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

Kills WordPress execution and displays HTML page with an error message.

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

Checks whether the given variable is a WordPress Error.

  |

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

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

| Version | Description | 
| [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | Introduced. |

## User Contributed Notes

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