I'm trying to populate a custom table called countries, with two rows of data. The custom table is created when the plugin is activated. The rows need to be added when the plugin is activated. The code for the custom table is fine, & the custom table is created. My code so far:
register_activation_hook( __FILE__, 'mp_insert_countries_rows' );
function mp_insert_countries_rows(){
global $wpdb;
$mp_insert_country = $wpdb->prefix . 'countries';
$insert_country_rows = $wpdb->insert(
$mp_insert_country,
array(
'id' => '1',
'name' => 'UK',
'labour_cost' => '20',
'overheads' => '0.45',
'profit' => '0.22'
),
array(
'id' => '2',
'name' =>'China',
'labour_cost' => '6',
'overheads' => '0.27',
'profit' => '0.17'
));
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $insert_country_rows );
}
How should I correct this? Thanks
WP_DEBUG
to true in wp-config.php file, what do you notice when you activate the plugin? Also are you really providing table structure for dbDelta function?The plugin generated 765 characters of unexpected output during activation.
I don't get anything on the actual plugin page . Thanks.dbDelta( $sql )
to create the table and$wpdb->insert( $table, $data, $format );
to insert the data (more here). You don't take the output from$wpdb->insert()
intodbDelta()
. Check it out and report back.