wpdb – Register custom table for WP to use in a plugin

Question

I am trying to add a custom table handler to $wpdb.

public function __construct() {
    $this->register_tables();
}

public function register_tables() {
    global $wpdb;

    $wpdb->tables[] = 'my_new_tablename';
}

public function testing() {
    global $wpdb;
    wp_die($wpdb->my_new_tablename);
}

But when running the testing() method, I realize that $wpdb->my_new_tablename is not defined.

How may I register my own table name and make it available at $wpdb->my_new_tablename, just like as if it was a native WP table?

0
Alvaro Franz 3 weeks 2021-11-06T10:43:07-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse