Creating custom tables

In pure PHP development, we create the database tables manually before moving onto the implementation phase. With the WordPress plugin-based architecture, it's certain that we might need to create custom tables using plugins in the later stages of the projects. Creating custom tables through plugins involves certain predefined procedures recommended by WordPress. Since table creation is a one-time task, we should implement the process on plugin activation or installation. Let's take a look at the code for creating custom database tables:

function create_custom_tables() {  global $wpdb;  require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );  $custom_table = $wpdb->prefix.'user_job_history';  if($wpdb->get_var("show ...

Get WordPress Development Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.