There’s this problem that has been bugging me all day now, and I hoped you could help me. I’m currently developing a plugin for WordPress, to support tourdates as a post type (it’s for a band website). For the tourdates I need to know the Venue, so I created the taxonomy Venue. Now I want to add meta data to the taxonomy so I tried adding a table to my WordPress database. This is what I’ve got so far:
global $scooby_db_version;
$scooby_db_version = '0.1';
new Venue();
class Venue {
function __construct(){
add_action('plugins_loaded', array(&$this, 'install'));
}
function install(){
global $scooby_db_version;
global $wpdb;
if(get_site_option('scooby_db_version') != $scooby_db_version){
$table_name = $wpdb->prefix."term_meta";
$sql = "
------- Taxonomy Meta -------
CREATE TABLE $table_name (
meta_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
term_id bigint(20) unsigned NOT NULL DEFAULT '0',
meta_key varchar(255) DEFAULT NULL,
meta_value longtext,
PRIMARY KEY (meta_id),
INDEX term_id (term_id),
INDEX meta_key (meta_key)
);";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
add_option('scooby_db_version', $scooby_db_version);
}
}
}
This does nothing at all. Appearantly it did work once, ’cause there is a entry in the options table, but it won’t update. It seems like the function is never called at all, but when it was (hence the db-entry) it did not create a table.
I’m really frustrated about this, because I can’t continue work on my plugin this way. Can you guys figure out what could be wrong? Why doesn’t it either call my function or update my database?
dbDelta is both handy and a bitch.
http://codex.wordpress.org/Creating_Tables_with_Plugins#Creating_or_Updating_the_Table
PRIMARY KEYand the definition of your primary key.KEYrather than its synonymINDEXand you must include at least oneKEY.