how to Get Database Table Prefix In WordPress?

Today, We want to share with you what is the prefix of wordpress tables by default.In this post we will show you get wordpress table prefix, hear for $wpdb->prefix we will give you demo and example for implement.In this post, we will learn about How To Get Last Insert Id In wpdb WordPress? with an example.

Get Database Table Prefix In WordPress

here you can get table prefix in WordPress

    $root = realpath($_SERVER["DOCUMENT_ROOT"]);
    require "$root/wp-blog-header.php";

    function get_table_prefix() {
        global $wpdb;
        $table_prefix = $wpdb->prefix . "posts";
        return $table_prefix;
    // echo get_table_prefix();

 * WordPress Database Table prefix.
$table_prefix  = 'pakainfo_';

// WebSite 2 prefix

// WebSite 3 prefix

function code_function()
    global $wpdb;

global $wpdb;

// Current & Active web site prefix
echo $wpdb->prefix;

global $wpdb;

// Results pakainfo_2_
echo $wpdb->prefix;

use another main property available in the gloabl $wpdb class defined as $wpdb->base_prefix.

Read Also:  PHP cUrl GET & POST Methods Example

global $wpdb;

// current & Active site prefix
echo $wpdb->prefix;

// main on root file wp-config.php defined prefix
echo $wpdb->base_prefix;

By default the WordPress database table prefix is wp_, you can change this prefix in the main db or some settings like as a wp-config.php. To change the database table prefix add a variable of $table_prefix to the wp-config.php file.

global $wpdb;

$my_table_name = $wpdb->prefix . 'my_table';
var_dump( $my_table_name );

I hope you get an idea about Retrieving and displaying data from WordPress database Table prefix.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.