Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to create a table by including the script that creates it in the main plugin file.

I have this:

register_activation_hook( __FILE__, 'vkrwps_agt' );
function vkrwps_agt() {
   global $wpdb;
   global $jal_db_version;

   $table_name = $wpdb->prefix . "attribute_groups";

   $sql = "CREATE TABLE $table_name (
  id int(11) NOT NULL AUTO_INCREMENT,
  attribute_name VARCHAR NOT NULL,
  attribute_group VARCHAR NOT NULL,
  PRIMARY KEY id (id)
    );";

   require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
   dbDelta( $sql );

} // end vkrwps_agt()

If I have that in my main plugin file, it works (it creates the table), but I put that code in another script called tables.php inside inc folder in my plugin root directory, because I want to include it within the main plugin file.

I tried the following but it does not work:

require 'inc/tables.php';

I get no error (e.g. file not found) but the table does not get created.

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.