How to create a custom table using custom code in WordPress? 



global $wpdb;
    global $charset_collate;
    $table_name = $wpdb->prefix . 'custom_table';
	$sql = "CREATE TABLE IF NOT EXISTS $table_name (
		`ID` int(20) NOT NULL AUTO_INCREMENT,
		`name` varchar(200)  NOT NULL,
		`mobile_number` varchar(200) NOT NULL,
		`email` varchar(20) NOT NULL,
		PRIMARY KEY (`ID`)
	)$charset_collate;";
    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    dbDelta( $sql );

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s