Creating a custom table API

Support MB Custom Table Creating a custom table API

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #6971
    kagoubkagoub
    Participant

    I can't seem to figure out how to use custom table API.

    "MB_Custom_Table_API::create( 'my_custom_table', array(
        'address' => 'TEXT NOT NULL',
        'phone'   => 'TEXT NOT NULL',
        'email'   => 'TEXT NOT NULL',
    ) );"

    Where should I put this code? I added it to functions.php where I have the metabox but it's no working for me.

    #6986
    Anh TranAnh Tran
    Keymaster

    Hi,

    It's recommended to use a hook like 'plugins_loaded', 'init' or better - activation hook to create a new table. In case of a theme, you can hook into 'init', like this:

    add_action( 'init', 'prefix_create_table' );
    function prefix_create_table() {
        if ( ! class_exists( 'MB_Custom_Table_API' ) ) {
            return;
        }
        MB_Custom_Table_API::create( 'my_custom_table', array(
            'address' => 'TEXT NOT NULL',
            'phone'   => 'TEXT NOT NULL',
            'email'   => 'TEXT NOT NULL',
        ), array( 'email' ) );
    }

    For more info, please see the sub-section E. in the section Notes of the documentation.

Viewing 2 posts - 1 through 2 (of 2 total)
  • The topic ‘Creating a custom table API’ is closed to new replies.