Get database prefix wordpress hosting

21st September 2013

If you are using WordPress multisite then depending on what blog you are using the database table prefix will be different. By default the WordPress database table prefix is wp_. you can change this prefix in the wp-config.php.

To change the database table prefix add a variable of $table_prefix to the wp-config.php file.

When you are using WordPress multisite the blog ID will be added to the end of the database table prefix.

Get database prefix wordpress hosting premium WordPress plugins     
    Only

To get data from your database WordPress uses a database class defined as $wpdb. you can get access to this object in any of your functions simply by using the global keyword.

The information you can get from this class is very useful when interacting with the database, this will store the last query, the last result and current site it needs to query.

If you are making custom queries to the WordPress database you should use this object to get the information for the current site. There is a property which is defined as prefix to get the current site database prefix.

If you are on the main site or have a single site install this value will stay the same, but on mutlisite installs of WordPress this property will change to whatever site you are on.

If I were to switch to site ID 2 then $wpdb->prefix will be newprefix_2_.

But there may be a time where you want to get the value of the prefix that was defined in the wp-config.php. even on a multisite blog. To get this value you need to use another property available in the $wpdb class defined as $wpdb->base_prefix .

Gain access to all tutorials

  • Premium tutorials covering WordPress, Laravel and VueJS
  • Download premium content
  • Download premium WordPress plugins
  • Only $5 a month
Watch this video!

Related articles

Change theme uri wordpress hostingChanging The Site URL On the Settings->General screen in a single site installation of WordPress, there are two fields named "WordPress Address (URL)" and "Site Address (URL)". They are...
Hosting two wordpress sites on one serverMultisite feature If you want multiple blogs using WordPress, use multisite feature to create what was referred to as a network of sites. This feature was implemented by merging WordPressMU...
Free wordpress hosting australia flagWordPress powers 26.4% of all websites on the Internet. Being so popular, it attracts a lot of attention. Not all of that attention is good. The negative attention that WordPress gets often...
Mysql change table prefix joomla hostingThere are few methods to determine your database prefix. The recommended method is to view the Global Configuration Database Settings Group from the administrator view of your Joomla! website....
Prefix database joomla hostingThere are few methods to determine your database prefix. The recommended method is to view the Global Configuration Database Settings Group from the administrator view of your Joomla! website....