diff --git a/wp-admin/includes/schema.php b/wp-admin/includes/schema.php index 6ff157975..b73c5a142 100644 --- a/wp-admin/includes/schema.php +++ b/wp-admin/includes/schema.php @@ -31,6 +31,7 @@ CREATE TABLE $wpdb->term_taxonomy ( CREATE TABLE $wpdb->term_relationships ( object_id bigint(20) NOT NULL default 0, term_taxonomy_id bigint(20) NOT NULL default 0, + term_order int(11) NOT NULL default 0, PRIMARY KEY (object_id,term_taxonomy_id), KEY term_taxonomy_id (term_taxonomy_id) ) $charset_collate; diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 1801e55d2..ff1a8925d 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -1033,6 +1033,8 @@ function wp_get_object_terms($object_ids, $taxonomies, $args = array()) { $orderby = 't.slug'; else if ( 'term_group' == $orderby ) $orderby = 't.term_group'; + else if ( 'term_order' == $orderby ) + $orderby = 'tr.term_order'; else $orderby = 't.term_id'; @@ -1249,6 +1251,18 @@ function wp_set_object_terms($object_id, $terms, $taxonomy, $append = false) { } } + $t = get_taxonomy($taxonomy); + if ( ! $append && $t->sort ) { + $values = array(); + $term_order = 0; + $final_term_ids = wp_get_object_terms($object_id, $taxonomy, 'fields=tt_ids'); + foreach ( $term_ids as $term_id ) + if ( in_array($term_id, $final_term_ids) ) + $values[] = $wpdb->prepare( "(%d, %d, %d)", $object_id, $term_id, ++$term_order); + if ( $values ) + $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id, term_order) VALUES " . join(',', $values) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)"); + } + return $tt_ids; } diff --git a/wp-includes/version.php b/wp-includes/version.php index 6d592939a..56cfaeb6d 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,6 +16,6 @@ $wp_version = '2.4-bleeding'; * * @global int $wp_db_version */ -$wp_db_version = 6825; +$wp_db_version = 6846; ?>