简短的exmaple我是怎么做的。。。(表命名不太正确。)
在这个例子中,我试图保存_description
$_POST变量。
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\');
}
}
术语元函数
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声明(您可以将其放在一些init function或functions.php中-由您决定)
global $wpdb;
$wpdb->tables[] = \'termmeta\';
$wpdb->termmeta = $wpdb->prefix.\'termmeta\';
表本身
$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");