0

Hi i have following code that adds table to database when the plugin is activated. For the moment they are only for input fields. I need to create a table for checkbox or yes/no. Thnaks

                $sql = "CREATE TABLE $easy_gallery_table (
                Id INT NOT NULL AUTO_INCREMENT, 
                name VARCHAR( 30 ) NOT NULL, 
                slug VARCHAR( 30 ) NOT NULL, 
                description TEXT NOT NULL, 
                thumbnail LONGTEXT NOT NULL, 
                thumbwidth INT, 
                thumbheight INT, 
                PRIMARY KEY Id (Id) 
                );";
            require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
            dbDelta( $sql );

1 Answer 1

1

You can add above code on plugin activation hook so that code run whenever you activate plugin.

For checkbox You need to define table column type as Boolean.

Dont forget to check table is already exist or not. otherwise it show error on second activation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.