Saving custom term value to the database in new table

short exmaple how i do it… (tables naming not really correct.)

in this example i am trying to save _description $_POST variable.

add_action ( 'edited_term', 'custom_edited_term', 10, 3);
function custom_edited_term($term_id, $tt_id, $taxonomy){
    if ( defined('DOING_AJAX') || defined('DOING_CRON') )
            return;

    $_POST = stripslashes_deep($_POST); 
    if (isset($_POST['_description']) && trim($_POST['_description']) != ''){
        update_term_meta($term_id, '_description', trim($_POST['_description']));
    } else {
        delete_term_meta($term_id, '_description');
    }
}

Terms Meta Functions

if (!function_exists('add_term_meta')){
    function add_term_meta($term_id, $meta_key, $meta_value, $unique = false) {
        if ( $the_term = wp_is_term_revision($term_id) )
            $term_id = $the_term;
        return add_metadata('term', $term_id, $meta_key, $meta_value, $unique);
    }
}


if (!function_exists('delete_term_meta')){
    function delete_term_meta($term_id, $meta_key, $meta_value="") {
        return delete_metadata('term', $term_id, $meta_key, $meta_value);
    }
}

if (!function_exists('get_term_meta')){
    function get_term_meta($term_id, $key, $single = false) {
        return get_metadata('term', $term_id, $key, $single);
    }       
}



if (!function_exists('update_term_meta')){
    function update_term_meta($term_id, $meta_key, $meta_value, $prev_value = false) {
        return update_metadata('term', $term_id, $meta_key, $meta_value, $prev_value);
    }
}

terms tables declaration (you can put it to some init function or functions.php – up to you)

global $wpdb;
$wpdb->tables[] = 'termmeta';
$wpdb->termmeta = $wpdb->prefix.'termmeta';

table itself

$wpdb->query("CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}termmeta` (
    `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`),
    KEY `meta_key` (`meta_key`),
    KEY `term_id` (`term_id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1");